Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, EditClassModel editClassModel)
        {
            var model = this.classesService.GetById <EditClassModel>(id);

            if (model == null)
            {
                return(this.BadRequest());
            }

            if (!this.ModelState.IsValid)
            {
                editClassModel.GroupTrainings = this.groupTrainingsService.GettAll <ClassGroupTrainingInListViewModel>();
                editClassModel.Trainers       = this.trainersService.GetAll <ClassTrainersInListViewModel>();

                return(this.View(editClassModel));
            }

            if (editClassModel.EndHour <= editClassModel.StartHour)
            {
                editClassModel.GroupTrainings = this.groupTrainingsService.GettAll <ClassGroupTrainingInListViewModel>();
                editClassModel.Trainers       = this.trainersService.GetAll <ClassTrainersInListViewModel>();

                this.ModelState.AddModelError(string.Empty, InvalidHours);

                return(this.View(editClassModel));
            }

            var classes = this.classesService.GettAll <ClassInListViewModel>();

            if (classes.Any(x => x.StartHour == editClassModel.StartHour && x.DayOfWeek == editClassModel.DayOfWeek))
            {
                editClassModel.GroupTrainings = this.groupTrainingsService.GettAll <ClassGroupTrainingInListViewModel>();
                editClassModel.Trainers       = this.trainersService.GetAll <ClassTrainersInListViewModel>();

                this.ModelState.AddModelError(string.Empty, DayAndTimeIsTakenError);

                return(this.View(editClassModel));
            }

            var editServiceModel = AutoMapperConfig.MapperInstance.Map <EditClassServiceModel>(editClassModel);

            await this.classesService.EditAsync(id, editServiceModel);

            return(this.RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public MResultModel EditClassInfo(EditClassModel inputM)
        {
            MResultModel resM;

            try
            {
                _classListBLL.EditClassInfo(inputM);
                resM = MResultModel.GetSuccessResultM("修改成功");
            }
            catch (ArgumentNullException ex)
            {
                resM = MResultModel.GetFailResultM(ex.Message);
            }
            catch (ArgumentException ex)
            {
                resM = MResultModel.GetFailResultM(ex.Message);
            }
            return(resM);
        }