public ActionResult Register(OrganizationMvcViewModel model) { if (User.Identity.IsAuthenticated) { _authorizationService.Logout(); } if (ModelState.IsValid == false) { return(View(model)); } OperationResult <ImageDto> imageResult = null; if (Request.Files.Count > 0) { var file = Request.Files[0]; var image = Mapper.Map <ImageDto>(file); imageResult = _imageService.SaveImage(image); } if (imageResult != null && !imageResult.Succeeded) { ModelState.AddModelError("", $"Ошибки при регистрации:</br>" + $"{string.Join("</br>", imageResult.Errors)}"); return(View(model)); } var organization = Mapper.Map <OrganizationDto>(model); organization.ImageId = imageResult?.Data.Id; var oranizationResult = _organizationService.Save(organization); if (!oranizationResult.Succeeded) { ModelState.AddModelError("", $"Ошибки при регистрации:</br>" + $"{string.Join("</br>", oranizationResult.Errors)}"); return(View(model)); } _authorizationService.Login(model.Email, model.Password); return(RedirectToAction("Index", "Home")); }
public ActionResult Edit(string id, OrganizationMvcViewModel model) { if (ModelState.IsValid == false) { return(View(model)); } if (string.IsNullOrEmpty(model.OwnerId)) { throw new HttpException((int)HttpStatusCode.InternalServerError, "Не указан идентификатор пользователя"); } OperationResult <ImageDto> imageResult = null; if (Request.Files.Count > 0) { var file = Request.Files[0]; var image = Mapper.Map <ImageDto>(file); imageResult = _imageService.SaveImage(image); } if (imageResult != null && !imageResult.Succeeded) { ModelState.AddModelError("", $"Ошибки при обновлении организации:</br>" + $"{string.Join("</br>", imageResult.Errors)}"); return(View(model)); } var organization = Mapper.Map <OrganizationDto>(model); organization.ImageId = imageResult?.Data.Id; var organizationResult = _organizationService.Save(organization); if (!organizationResult.Succeeded) { ModelState.AddModelError("", $"Ошибки при обновлении организации:</br>" + $"{string.Join("</br>", organizationResult.Errors)}"); return(View(model)); } return(RedirectToAction("Index", "Home")); }