예제 #1
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"));
        }
예제 #2
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"));
        }