当前位置: 首页>>代码示例>>C#>>正文


C# Photo.ConvertToUnixTimestamp方法代码示例

本文整理汇总了C#中Photo.ConvertToUnixTimestamp方法的典型用法代码示例。如果您正苦于以下问题:C# Photo.ConvertToUnixTimestamp方法的具体用法?C# Photo.ConvertToUnixTimestamp怎么用?C# Photo.ConvertToUnixTimestamp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Photo的用法示例。


在下文中一共展示了Photo.ConvertToUnixTimestamp方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UploadPhoto

        /// <summary>
        /// Processes and uploads a photo from the currently signed-in user to PhotoHunt.
        /// </summary>
        /// <param name="context">The HttpContext containing the request with an image in it.
        /// </param>
        /// <param name="user">The currently sign-in user.</param>
        /// <param name="themeId">The id for the theme that the photo will be added to.</param>
        /// <param name="themeDisplayName">The display name for the theme that the photo will be
        /// added to.</param>
        /// <returns>The Photo object representing the uploaded photo.</returns>
        public static Photo UploadPhoto(HttpContext context, User user, Theme selectedTheme)
        {
            // User will be NULL if there isn't someone signed in.
            if (user == null)
            {
                context.Response.StatusCode = 401;
                context.Response.StatusDescription = "Unauthorized request.";
                return null;
            }

            // path is uploads/theme/userid/filename
            HttpPostedFile upload = context.Request.Files["image"];
            string path = context.Server.MapPath("..") + "\\uploads\\";
            Directory.CreateDirectory(path);
            path += selectedTheme.displayName + "\\";
            Directory.CreateDirectory(path);
            path += user.id + "\\";
            Directory.CreateDirectory(path);

            path += upload.FileName;
            upload.SaveAs(path);

            string urlpath = "uploads/" + selectedTheme.displayName + "/" + user.id + "/" +
                    upload.FileName;
            string thumbPath = ResizePhoto(path, urlpath, user, selectedTheme.displayName, upload);

            // Save the photo using EF
            Photo dbPhoto = new Photo();

            dbPhoto.ownerUserId = user.id;
            dbPhoto.ownerDisplayName = user.googleDisplayName;
            dbPhoto.ownerProfileUrl = user.googlePublicProfileUrl;
            dbPhoto.ownerProfilePhoto = user.googlePublicProfilePhotoUrl;
            dbPhoto.themeId = selectedTheme.id;
            dbPhoto.themeDisplayName = selectedTheme.displayName;
            dbPhoto.numVotes = 0;
            dbPhoto.voted = false;
            dbPhoto.created = (long) dbPhoto.ConvertToUnixTimestamp(DateTime.Now);
            dbPhoto.fullsizeUrl = BASE_URL + urlpath;
            dbPhoto.thumbnailUrl = thumbPath;

            // Save to set the ID for the remaining members.
            PhotohuntContext db = new PhotohuntContext();
            db.Photos.Add(dbPhoto);
            db.SaveChanges();

            dbPhoto.photoContentUrl = BASE_URL + "photo.aspx?photoId=" + dbPhoto.id;

            // Set the default theme photo id to this one
            dbPhoto.voteCtaUrl = BASE_URL +
                    "photo.aspx" + "?photoId=" + dbPhoto.id + "&action=vote";
            db.SaveChanges();

            // Set the uploaded photo to the preview for the theme.
            Theme dbTheme = db.Themes.First(theme => theme.id == selectedTheme.id);
            dbTheme.previewPhotoId = dbPhoto.id;
            db.SaveChanges();

            return dbPhoto;
        }
开发者ID:ahszn,项目名称:gplus-photohunt-server-csharp,代码行数:70,代码来源:PhotosHelper.cs


注:本文中的Photo.ConvertToUnixTimestamp方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。