예제 #1
0
 public ActionResult AddPost(PostVM post, HttpPostedFileBase fileUpload)
 {
     try
     {
         if (ModelState.IsValid)
         {
             if (fileUpload != null)
             {
                 var            res             = ImageHelper.ScaleImage(Image.FromStream(fileUpload.InputStream, true, true), 600, 400);
                 ImageConverter _imageConverter = new ImageConverter();
                 byte[]         xByte           = (byte[])_imageConverter.ConvertTo(res, typeof(byte[]));
                 post.Photo = xByte;
             }
             if (dataHelper.AddMessage(post, User.Identity.Name))
             {
                 return(RedirectToAction("Index", new { page = 1, themeId = post.Theme }));
             }
             else
             {
                 return(View("Error"));
             }
         }
         else
         {
             var themes = dataHelper.GetThemes();
             if (!User.IsInRole("admin"))
             {
                 themes.RemoveAt(0);
             }
             ViewBag.Themes = themes.Select(x => new SelectListItem {
                 Text = x.Name, Value = x.Id.ToString()
             }).ToList();
             return(View(post));
         }
     }
     catch (Exception ex)
     {
         logger.ErrorMessage("305", ex);
         return(View("Error", new Error()
         {
             ExDescription = ex.Message
         }));
     }
 }