public ActionResult AddAdvert(AdvertVM advert, HttpPostedFileBase fileUpload) { try { if (ModelState.IsValid) { if (fileUpload != null) { var res = ImageHelper.ScaleImage(Image.FromStream(fileUpload.InputStream, true, true), 300, 200); ImageConverter _imageConverter = new ImageConverter(); byte[] xByte = (byte[])_imageConverter.ConvertTo(res, typeof(byte[])); advert.Photo = xByte; } if (dataHelper.AddAdvert(advert, User.Identity.Name)) { return(RedirectToAction("Index", "Advert")); } else { return(View("Error")); } } else { SetViewBag(); return(View(advert)); } } catch (Exception ex) { logger.ErrorMessage("305", ex); return(View("Error", new Error() { ExDescription = ex.Message })); } }