Example #1
0
        public ActionResult AvailableSubjectsGridViewUpdate([ModelBinder(typeof(DevExpressEditorsBinder))]
                                                            Models.AvailableSubjects item)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (string.IsNullOrEmpty(item.SubjectCode))
                    {
                        item.SubjectCode = new IdHelpers().GenerateSubjectCode(item.AvailableCourseId ?? 0);
                    }

                    var schedulesHelper = new SchedulesHelper();
                    schedulesHelper.UpdateSchedule(item);
                    // Insert here a code to update the item in your model
                    unitOfWork.AvailableSubjectsRepo.Update(item);
                    unitOfWork.Save();
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                }
            }
            else
            {
                ViewData["EditError"] = "Please, correct all errors.";
            }

            var model = unitOfWork.AvailableSubjectsRepo.Get(
                includeProperties: "AvailableCourses,Subjects,UserDetails");

            return(PartialView("_AvailableSubjectsGridView", model));
        }
Example #2
0
        public ActionResult CopyAvailableSubjectsPartial([ModelBinder(typeof(DevExpressEditorsBinder))]
                                                         AvailableCourses item,
                                                         [ModelBinder(typeof(DevExpressEditorsBinder))]
                                                         bool?isPost)
        {
            if (item == null)
            {
                return(PartialView(item));
            }
            var availableCourses = unitOfWork.AvailableCoursesRepo
                                   .Fetch(m => m.SchoolYearId == item.SchoolYearId && m.AvailableSubjects.Any()).ToList();

            ViewBag.AvailableCourses = availableCourses;
            if (isPost == true)
            {
                foreach (var i in unitOfWork.AvailableSubjectsRepo.Get(x =>
                                                                       x.AvailableCourseId == item.AvailableCourseId))
                {
                    var course = unitOfWork.AvailableCoursesRepo.Find(m => m.Id == item.DestinationAvailableCourseId);
                    i.SubjectCode = new IdHelpers().GenerateSubjectCode(course.Id);

                    var schedulesHelper = new SchedulesHelper();

                    var availableSuject = new Models.AvailableSubjects()
                    {
                        AvailableCourseId = item.DestinationAvailableCourseId,
                        Schedule          = i.Schedule,
                        SubjectCode       = i.SubjectCode,
                        SubjectId         = i.SubjectId,
                        TeacherId         = i.TeacherId,
                    };
                    schedulesHelper.GenerateSchedule(availableSuject);
                    unitOfWork.AvailableSubjectsRepo.Insert(availableSuject);
                    unitOfWork.Save();
                }

                return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
            }


            return(PartialView(item));
        }
Example #3
0
        public ActionResult AvailableSubjectsGridViewAddNew([ModelBinder(typeof(DevExpressEditorsBinder))]
                                                            Models.AvailableSubjects item)
        {
            if (unitOfWork.AvailableSubjectsRepo
                .Fetch(m => m.SubjectId == item.SubjectId && m.AvailableCourseId == item.AvailableCourseId).Any())
            {
                ModelState.AddModelError("SubjectId", "Already Added Subject to this course and school year");
            }
            // var model = new object[0];
            if (ModelState.IsValid)
            {
                try
                {
                    // Insert here a code to insert the new item in your model
                    var course = unitOfWork.AvailableCoursesRepo.Find(m => m.Id == item.AvailableCourseId);
                    item.SubjectCode = new IdHelpers().GenerateSubjectCode(course.Id);

                    var schedulesHelper = new SchedulesHelper();
                    schedulesHelper.GenerateSchedule(item);
                    unitOfWork.AvailableSubjectsRepo.Insert(item);
                    unitOfWork.Save();
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                }
            }
            else
            {
                ViewData["EditError"] = "Please, correct all errors.";
            }

            var model = unitOfWork.AvailableSubjectsRepo.Get(
                includeProperties: "AvailableCourses,Subjects,UserDetails");

            return(PartialView("_AvailableSubjectsGridView", model));
        }