Exemplo n.º 1
0
        public async Task EditAsync(EditTrainingCourseViewModel viewModel)
        {
            var course = await _courses.FirstAsync(a => a.Id == viewModel.Id);
            _mappingEngine.Map(viewModel, course);
            course.LasModifierId = _userManager.GetCurrentUserId();

        }
Exemplo n.º 2
0
        public virtual async Task<ActionResult> Edit(EditTrainingCourseViewModel viewModel)
        {
            if (await _trainingCourseService.IsExistCourseCode(viewModel.CourseCode, viewModel.Id, viewModel.TrainingCenterId))
                this.AddErrors("CourseCode", "یک دوره با این کد برای مرکز قبلا در سیستم ثبت شده است");
            if (!await _trainingCourseService.IsInDb(viewModel.Id))
                this.AddErrors("CourseCode", "دوره کارآموزی مورد نظر توسط یکی از کاربران در شبکه،حذف شده است");

            if (!ModelState.IsValid)
            {
                return new JsonNetResult
                {
                    Data =
                        new
                        {
                            success = false,
                            View = this.RenderPartialViewToString(MVC.TrainingCourse.Views._Edit, viewModel)
                        }
                };
            }
            await _trainingCourseService.EditAsync(viewModel);
            var message = await _unitOfWork.ConcurrencySaveChangesAsync();
            if (message.HasValue()) this.AddErrors("CourseCode", string.Format(message, "دروه کارآموزی"));

            if (!ModelState.IsValid)
                return new JsonNetResult
                {
                    Data =
                        new
                        {
                            success = false,
                            View =
                                this.RenderPartialViewToString(MVC.TrainingCourse.Views._Edit, viewModel)
                        }
                };
            var course = await _trainingCourseService.GetTrainingCourseViewModel(viewModel.Id);
            return new JsonNetResult
            {
                Data =
                    new
                    {
                        success = true,
                        View = this.RenderPartialViewToString(MVC.TrainingCourse.Views._TrainingCourseItem, course)
                    }
            };
        }