Ejemplo n.º 1
0
        public IActionResult EditPost(EditCreateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(NotFound());
            }

            _instructorRepository.Update(model.Instructor);

            var insId = model.Instructor.InstructorId;

            foreach (var data in model.AssignedCourseData)
            {
                if (data.Assigned)
                {
                    var isExist = IsExistModel(_courseAssignmentRepository.GetAll(), insId, data.CourseId);

                    if (!isExist)
                    {
                        _courseAssignmentRepository.Add(new CourseAssignment()
                        {
                            CourseId     = data.CourseId,
                            InstructorId = model.Instructor.InstructorId
                        });
                    }

                    //
                }
                else
                {
                    var isExist = IsExistModel(_courseAssignmentRepository.GetAll(), insId, data.CourseId);
                    if (isExist)
                    {
                        var filter = _courseAssignmentRepository
                                     .GetByFiler(x => x.InstructorId == insId && x.CourseId == data.CourseId)
                                     .FirstOrDefault();
                        _courseAssignmentRepository.Delete(filter);
                    }

                    //
                }

                //
            }

            //

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public IActionResult EditPost(CreateInstructorViewModel model)
        {
            if (ModelState.IsValid)
            {
                _instructorRepository.Update(model.Instructor);

                var instructorId = model.Instructor.InstructorId;

                if (model.AssignedCourseData != null)
                {
                    foreach (var data in model.AssignedCourseData)
                    {
                        {
                            if (data.Assigned)
                            {
                                var isExist = IsExist(_courseAssignmentRepository.GetAll(), instructorId, data.CourseId);

                                if (!isExist)
                                {
                                    _courseAssignmentRepository.Add(new CourseAssignment()
                                    {
                                        CourseId = data.CourseId, InstructorId = instructorId
                                    });
                                }
                            }
                            else
                            {
                                var isExist = IsExist(_courseAssignmentRepository.GetAll(), instructorId, data.CourseId);

                                if (isExist)
                                {
                                    var filter = _courseAssignmentRepository
                                                 .GetByFiler(x => x.CourseId == data.CourseId && x.InstructorId == instructorId)
                                                 .FirstOrDefault();

                                    _courseAssignmentRepository.Delete(filter);
                                }
                            }
                        }

                        return(RedirectToAction("Index"));
                    }
                }

                return(View("Create"));
            }

            return(View("Edit"));
        }