public IHttpActionResult UpdateMenu() { var menuModel = new JavaScriptSerializer().Deserialize <MenuModel>(HttpContext.Current.Request.Form.Get(0)); var menuDto = Mapper.Map <MenuDTO>(menuModel); if (menuDto.IsImageChange) { if (!HttpContext.Current.Request.Files.AllKeys.Any()) { throw new ValidationException(ErrorCodes.EmptyCategoryImage); } var httpPostedFile = HttpContext.Current.Request.Files[0]; if (httpPostedFile == null) { throw new ValidationException(ErrorCodes.EmptyCategoryImage); } if (httpPostedFile.ContentLength > 2 * 1024 * 1000) { throw new ValidationException(ErrorCodes.ImageExceedSize); } if (Path.GetExtension(httpPostedFile.FileName).ToLower() != ".jpg" && Path.GetExtension(httpPostedFile.FileName).ToLower() != ".png" && Path.GetExtension(httpPostedFile.FileName).ToLower() != ".jpeg") { throw new ValidationException(ErrorCodes.InvalidImageType); } menuDto.Image = new MemoryStream(); httpPostedFile.InputStream.CopyTo(menuDto.Image); } _menuFacade.UpdateMenu(menuDto, UserId, HostingEnvironment.MapPath("~/Images/")); return(Ok()); }