public virtual async Task<ActionResult> Edit(EditTitleViewModel viewModel) { if (await _titleService.IsByNameExist(viewModel.Name, viewModel.Id, viewModel.Type, viewModel.Category)) this.AddErrors("Name", "یک عنوان با این نام ، نوع و گروه در سیستم ثبت شده است"); if(!await _titleService.IsInDb(viewModel.Id)) this.AddErrors("Name", "عنوان مورد نظر توسط یکی از کاربران در شبکه، حذف شده است"); if (!ModelState.IsValid) { return new JsonNetResult { Data = new { success = false, View = this.RenderPartialViewToString(MVC.Title.Views._Edit, viewModel) } }; } await _titleService.EditAsync(viewModel); var message = await _unitOfWork.ConcurrencySaveChangesAsync(); if (message.HasValue()) this.AddErrors("Name", string.Format(message, "عنوان")); if (!ModelState.IsValid) { return new JsonNetResult { Data = new { success = false, View = this.RenderPartialViewToString(MVC.Title.Views._Edit, viewModel) } }; } var title = await _titleService.GetTitleViewModel(viewModel.Id); return new JsonNetResult { Data = new { success = true, View = this.RenderPartialViewToString(MVC.Title.Views._TitleItem, title) } }; }
public async Task EditAsync(EditTitleViewModel viewModel) { var title = await _titles.FirstAsync(a => a.Id == viewModel.Id); _mappingEngine.Map(viewModel, title); title.LasModifierId = _userManager.GetCurrentUserId(); }