Пример #1
0
        public ActionResult Create()
        {
            if (!_permissionService.Authorize("ManageAcadmicYear"))
            {
                return(AccessDeniedView());
            }

            var model = new AcadmicYearModel();

            return(View(model));
        }
Пример #2
0
        public ActionResult Edit(AcadmicYearModel model, FormCollection frm, bool continueEditing)
        {
            if (!_permissionService.Authorize("ManageAcadmicYear"))
            {
                return(AccessDeniedView());
            }

            var user = _userContext.CurrentUser;
            // Check for duplicate acadmicyear, if any
            var checkAcadmicYear = _smsService.CheckAcadmicYearExists(model.Name, model.Id);

            if (checkAcadmicYear)
            {
                ModelState.AddModelError("Name", "AcadmicYear with the same name already exists. Please choose a different name.");
            }

            if (ModelState.IsValid)
            {
                var objAcadmicYear = _smsService.GetAcadmicYearById(model.Id);
                if (objAcadmicYear != null)
                {
                    model.CreatedOn           = objAcadmicYear.CreatedOn;
                    objAcadmicYear            = model.ToEntity(objAcadmicYear);
                    objAcadmicYear.ModifiedOn = DateTime.Now;

                    if (model.IsActive)
                    {
                        _smsService.DeactivateAllAcadmicYears();
                    }

                    _smsService.UpdateAcadmicYear(objAcadmicYear);
                }
            }
            else
            {
                return(View(model));
            }

            SuccessNotification("Acadmic Year updated successfully.");
            if (continueEditing)
            {
                return(RedirectToAction("Edit", new { id = model.Id }));
            }
            return(RedirectToAction("List"));
        }
Пример #3
0
        public PartialViewResult AcadmicYear()
        {
            var model = new AcadmicYearModel();

            model.AvailableAcadmicYears = _smsService.GetAllAcadmicYears(null).Select(x => new SelectListItem()
            {
                Text     = x.Name,
                Value    = x.Name,
                Selected = x.IsActive ? true : false
            }).ToList();

            var activeYear = model.AvailableAcadmicYears.FirstOrDefault(x => x.Selected);

            if (activeYear != null)
            {
                model.Name = activeYear.Value;
                _userContext.CurrentAcadmicYear = _smsService.GetAcadmicYearByName(model.Name);
            }

            return(PartialView(model));
        }
Пример #4
0
        public ActionResult Edit(int id)
        {
            if (!_permissionService.Authorize("ManageAcadmicYear"))
            {
                return(AccessDeniedView());
            }

            if (id == 0)
            {
                throw new ArgumentNullException("id");
            }

            var model          = new AcadmicYearModel();
            var objAcadmicYear = _smsService.GetAcadmicYearById(id);

            if (objAcadmicYear != null)
            {
                model = objAcadmicYear.ToModel();
            }
            return(View(model));
        }
Пример #5
0
        public ActionResult Create(AcadmicYearModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize("ManageAcadmicYear"))
            {
                return(AccessDeniedView());
            }

            // Check for duplicate acadmicyear, if any
            var checkAcadmicYear = _smsService.CheckAcadmicYearExists(model.Name, model.Id);

            if (checkAcadmicYear)
            {
                ModelState.AddModelError("Name", "Acadmic Year with the same name already exists.");
            }

            if (ModelState.IsValid)
            {
                var objAcadmicYear = model.ToEntity();
                objAcadmicYear.CreatedOn = objAcadmicYear.ModifiedOn = DateTime.Now;
                objAcadmicYear.UserId    = _userContext.CurrentUser.Id;

                if (model.IsActive)
                {
                    _smsService.DeactivateAllAcadmicYears();
                }

                _smsService.InsertAcadmicYear(objAcadmicYear);
                SuccessNotification("Acadmic Year created successfully.");
                if (continueEditing)
                {
                    return(RedirectToAction("Edit", new { id = objAcadmicYear.Id }));
                }
            }
            else
            {
                return(View(model));
            }
            return(RedirectToAction("List"));
        }
Пример #6
0
 public static AcadmicYear ToEntity(this AcadmicYearModel model, AcadmicYear destination)
 {
     return(model.MapTo(destination));
 }
Пример #7
0
 public static AcadmicYear ToEntity(this AcadmicYearModel model)
 {
     return(model.MapTo <AcadmicYearModel, AcadmicYear>());
 }