Esempio n. 1
0
 public static BllPost ToBllPost(this UploadPostViewModel photo, int userId)
 {
     return(new BllPost
     {
         Name = photo.Name,
         Image = ToByteArray(photo.ImageFile),
         Description = photo.Description,
         Tags = ToTags(photo.Tags),
         UploadDate = DateTime.Now,
         UserLikesEntity = new List <BllUserLikesEntity>(),
         User = new BllUser {
             UserId = userId
         }
     });
 }
        public async Task <ActionResult> Upload(UploadPostViewModel model)
        {
            if (!(await Authorized()))
            {
                return(RedirectToAction("Login", "Account"));
            }
            if (!ModelState.IsValid)
            {
                return(View(model));
            }


            string uploadedImageUrl = null;

            if (model.ImageFile != null)
            {
                if (model.ImageFile.ContentLength > 1024 * 1024 * 4)
                {
                    ViewBag.UploadPostFormVisible = true;
                    AddError("Image file size must not exceed 4MB");

                    return(View(model));
                }
                else
                {
                    AmazonBucketClient client = new AmazonBucketClient();
                    uploadedImageUrl = client.UploadFile(model.ImageFile.InputStream, RandomString());
                }
            }

            var mentionedUserIds = System.Web.Helpers.Json.Decode <string[]>(model.JsonMentions);

            var result = await PostsManager.UploadPost(UserToken, new PostModel { Content = model.PostContent, ImageUrl = uploadedImageUrl, Mentions = mentionedUserIds, Permission = model.PostPermission });

            if (result)
            {
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                return(ErrorView("Post was not uploaded"));
            }
        }
Esempio n. 3
0
 public ActionResult UploadPost(UploadPostViewModel photo)
 {
     _postService.Add(photo.ToBllPost(_accountService.GetUserByLogin(User.Identity.Name).UserId));
     return(RedirectToAction("Index", "Profile"));
 }