public async Task <IActionResult> Edit(int id, ResidenceModel model, List <IFormFile> uploadImages) { model.ResidenceCategories = _iCategoryBLL.GetAllCategories(); model.UserId = Convert.ToInt32(User.FindFirst(ClaimTypes.SerialNumber).Value); var authorizationResult = await _iAuthorizationService.AuthorizeAsync(User, model, Constants.Update); if (authorizationResult.Succeeded) { if (ModelState.IsValid) { if (uploadImages.Count != 0) { _iResidenceBLL.RemoveResidenceImage(_iHostingEnvironment.ContentRootPath + Constants.wwwroot, id); model.Images = new List <string>(); try { foreach (var image in uploadImages) { await ImageProcesser.UploadeAndResize(_iHostingEnvironment, image); model.Images.Add(ImageProcesser.ReturnFileTarget()); } } catch (Exception e) { ModelState.AddModelError("Images", e.Message); return(View(model)); } } _iResidenceBLL.UpdateResidence(model); return(RedirectToAction("Items")); } else { return(View(model)); } } else if (User.Identity.IsAuthenticated) { return(new ForbidResult()); } else { return(new ChallengeResult()); } }
public async Task <IActionResult> Create(ResidenceModel model, List <IFormFile> uploadImages) { model.ResidenceCategories = _iCategoryBLL.GetAllCategories(); if (ModelState.IsValid) { model.UserId = Convert.ToInt32(User.FindFirst(ClaimTypes.SerialNumber).Value); if (uploadImages.Count != 0) { model.Images = new List <string>(); try { foreach (var image in uploadImages) { await ImageProcesser.UploadeAndResize(_iHostingEnvironment, image); model.Images.Add(ImageProcesser.ReturnFileTarget()); } } catch (Exception e) { ModelState.AddModelError("Images", e.Message); return(View(model)); } } _iResidenceBLL.CreateResidence(model); return(RedirectToAction("Items")); } else { return(View(model)); } }