示例#1
0
 public async Task EditAsync(EditInstitutionViewModel viewModel)
 {
     var institution = await _institutions.FirstAsync(a => a.Id == viewModel.Id);
     _mappingEngine.Map(viewModel, institution);
     institution.LasModifierId = _userManager.GetCurrentUserId();
 }
        public virtual async Task<ActionResult> Edit(EditInstitutionViewModel viewModel)
        {
            if (!await _institutionService.IsInDb(viewModel.Id))
                this.AddErrors("Name", "موسسه آموزشی مورد نظر توسط یکی از کاربران در شبکه،حذف شده است");

            if (!ModelState.IsValid)
            {
                return new JsonNetResult
                {
                    Data = new
                    {
                        success = false,
                        View = this.RenderPartialViewToString(MVC.Institution.Views._Edit, viewModel)
                    }
                };
            }

            await _institutionService.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.Institution.Views._Edit, viewModel)
                    }
                };

            var institution = await _institutionService.GetInstitutionViewModel(viewModel.Id);
            return new JsonNetResult
            {
                Data = new
                {
                    success = true,
                    View = this.RenderPartialViewToString(MVC.Institution.Views._InstitutionItem, institution)
                }
            };
        }