public async Task <IActionResult> ProjectEditPost(int id, ProjectWorkModel model) { if (ModelState.IsValid) { var result = await _crudService.Edit(id, model, Token, ProjectService.ProjectEntity); AddMessageToModel(model, result.Message, !result.Success); } else { AddModelStateErrors(model); } return(View("Edit", model)); }
public async Task <IActionResult> AffectedFieldEditPost(int id, AffectedFieldWorkModel model) { if (ModelState.IsValid) { var result = await _crudService.Edit(id, model, Token, SettingService.AffectedFieldEntity); AddMessageToModel(model, result.Message, !result.Success); } else { AddModelStateErrors(model); } return(View("AffectedField/Edit", model)); }
public virtual ActionResult Edit(TViewModel viewModel) { if (ModelState.IsValid) { var dto = _service.GetByID(viewModel.ID); Mapper.Map(viewModel, dto); _service.Edit(dto); viewModel = (Mapper.Map <TViewModel>(dto)); } return(View(viewModel)); }
public ActionResult Edit(WorkcenterDTO workcenterDto) { try { //workcenterViewModel.ModelState = this.ModelState; if (ModelState.IsValid) { var workcenter = AutoMapperWebUtil.WorkcenterDtoToEntities(workcenterDto); workcenterCrudService.Edit(workcenter); return(RedirectToAction("Index")); } } catch (ValidationException ex) { ControllerExtension.ActionsOnException(logger, ex, ModelState); return(Json(ex, JsonRequestBehavior.AllowGet)); } // workcenterViewModel.ModelState = this.ModelState; return(Json(workcenterDto, JsonRequestBehavior.AllowGet)); }
/// <summary> /// Edits the entity in the the persistence infrastructure layer /// </summary> /// <param name="id">Id of the entity to be edited</param> /// <param name="entity">Entity to be edited</param> /// <returns>Tuple representing success and affected dto</returns> public virtual Tuple <bool, TDomainEntity> Edit(int id, TDomainEntity entity) { try { // Validate entity if (!entity.IsValid(_logger)) { throw new ArgumentException(Literals.p_EntityNotValid.ParseParameter(entity.GetType().ToString()), nameof(entity)); } // Adapt domain entity to model entity TModelEntity modelEntity = _domainToModelAdapter.Adapt(entity); // edit in the database Tuple <bool, TModelEntity> result = _crudService.Edit(id, modelEntity); return(Tuple.Create(result.Item1, _modelToDomainAdapter.Adapt(result.Item2))); } catch (Exception ex) { _logger.LogError(ex, Literals.p_ErrorEditingDtoOfTypeX.ParseParameter(typeof(TDomainEntity).Name)); throw; } }
public async Task <IActionResult> Edit(int id, UserWorkModel model) { Task select = GetLanguages(model); if (ModelState.IsValid) { Task userTask = _crudService.Edit(id, model, Token, UserService.UserEntity).ContinueWith(async r => { var result = r.Result; if (result.Success) { var user = MyUser; user.Firstname = model.Firstname; user.Lastname = model.Lastname; user.Email = model.Email; await UserLogin(user, Token); } if (!model.UseLdaplogin) { model.LdapUrl = null; } AddMessageToModel(model, result.Message, !result.Success); }); Task passwordTask = Task.CompletedTask; if (!string.IsNullOrEmpty(model.OldPassword) && !string.IsNullOrEmpty(model.Password) && !string.IsNullOrEmpty(model.ConfirmPassword)) { if (model.Password == model.ConfirmPassword) { passwordTask = _crudService.PartialEdit(id, CreatePatchList(CreatePatchModel("password", $"{model.OldPassword};;;{model.Password}")), Token, UserService.UserEntity).ContinueWith(r => { var passwordResult = r.Result; if (passwordResult.Success) { AddMessageToModel(model, "Password was changed!", false); } else { AddMessageToModel(model, passwordResult.Message); } }); } else { AddMessageToModel(model, "Password and cofirmed password are not equal! Password wasn't changed."); } } await Task.WhenAll(userTask, passwordTask); } else { AddModelStateErrors(model); } await Task.WhenAll(select); return(View(model)); }