public ActionResult Create()
        {
            if (!_permissionService.Authorize("ManageFeeCategory"))
            {
                return(AccessDeniedView());
            }

            var model = new FeeCategoryModel();

            model.AvailableAcadmicYears = _smsService.GetAllAcadmicYears().Select(x => new SelectListItem()
            {
                Text  = x.Name.Trim(),
                Value = x.Id.ToString(),
            }).ToList();

            model.AvailableCategories = _smsService.GetAllCategories().Select(x => new SelectListItem()
            {
                Text  = x.Name.Trim(),
                Value = x.Id.ToString(),
            }).OrderBy(x => x.Text).ToList();

            model.AvailableClassDivisions = _smsService.GetAllClassRoomDivisions().Select(x => new SelectListItem()
            {
                Text  = x.Class.Name.Trim() + " " + x.Division.Name,
                Value = x.Id.ToString(),
            }).OrderBy(x => x.Text).ToList();
            return(View(model));
        }
        public ActionResult List()
        {
            if (!_permissionService.Authorize("ManageFeeCategory"))
            {
                return(AccessDeniedView());
            }

            var model = new FeeCategoryModel();

            return(View(model));
        }
        public ActionResult Edit(int id)
        {
            if (!_permissionService.Authorize("ManageFeeCategory"))
            {
                return(AccessDeniedView());
            }

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

            var model          = new FeeCategoryModel();
            var objFeeCategory = _smsService.GetFeeCategoryById(id);

            if (objFeeCategory != null)
            {
                model = objFeeCategory.ToModel();
            }

            model.AvailableAcadmicYears = _smsService.GetAllAcadmicYears().Select(x => new SelectListItem()
            {
                Text     = x.Name.Trim(),
                Value    = x.Id.ToString(),
                Selected = model.AcadmicYearId > 0 ? model.AcadmicYearId == x.Id : false
            }).ToList();

            model.AvailableCategories = _smsService.GetAllCategories().Select(x => new SelectListItem()
            {
                Text     = x.Name.Trim(),
                Value    = x.Id.ToString(),
                Selected = model.CategoryId > 0 && model.CategoryId == x.Id
            }).OrderBy(x => x.Text).ToList();

            model.AvailableClassDivisions = _smsService.GetAllClassRoomDivisions().Select(x => new SelectListItem()
            {
                Text     = x.Class.Name.Trim() + " " + x.Division.Name,
                Value    = x.Id.ToString(),
                Selected = model.ClassDivisionId > 0 && model.ClassDivisionId == x.Id
            }).OrderBy(x => x.Text).ToList();
            return(View(model));
        }
        public ActionResult Create(FeeCategoryModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize("ManageFeeCategory"))
            {
                return(AccessDeniedView());
            }

            if (model.CategoryId == 0 || model.ClassDivisionId == 0 || model.AcadmicYearId == 0)
            {
                if (model.CategoryId == 0)
                {
                    ModelState.AddModelError("CategoryId", "Please select category");
                }

                if (model.ClassDivisionId == 0)
                {
                    ModelState.AddModelError("ClassDivisionId", "Please select class division");
                }

                if (model.AcadmicYearId == 0)
                {
                    ModelState.AddModelError("AcadmicYearId", "Please select acadmic year");
                }

                model.AvailableAcadmicYears = _smsService.GetAllAcadmicYears().Select(x => new SelectListItem()
                {
                    Text     = x.Name.Trim(),
                    Value    = x.Id.ToString(),
                    Selected = model.AcadmicYearId > 0 ? model.AcadmicYearId == x.Id : false
                }).ToList();

                model.AvailableCategories = _smsService.GetAllCategories().Select(x => new SelectListItem()
                {
                    Text     = x.Name.Trim(),
                    Value    = x.Id.ToString(),
                    Selected = model.CategoryId > 0 && model.CategoryId == x.Id
                }).OrderBy(x => x.Text).ToList();

                model.AvailableClassDivisions = _smsService.GetAllClassRoomDivisions().Select(x => new SelectListItem()
                {
                    Text     = x.Class.Name.Trim() + " " + x.Division.Name,
                    Value    = x.Id.ToString(),
                    Selected = model.ClassDivisionId > 0 && model.ClassDivisionId == x.Id
                }).OrderBy(x => x.Text).ToList();
                return(View(model));
            }

            // Check for duplicate classroom, if any
            var checkFeeCategory = _smsService.CheckFeeCategoryExists(model.CategoryId, model.ClassDivisionId, model.AcadmicYearId, model.Id);

            if (checkFeeCategory)
            {
                ModelState.AddModelError("CategoryId", "A Fee Category with the same category, class division or acadmic year exist!");
            }

            if (ModelState.IsValid)
            {
                var objFeeCategory = model.ToEntity();
                objFeeCategory.CreatedOn    = objFeeCategory.ModifiedOn = DateTime.Now;
                objFeeCategory.UserId       = _userContext.CurrentUser.Id;
                objFeeCategory.CategoryName = _smsService.GetCategoryById(model.CategoryId).Name;
                _smsService.InsertFeeCategory(objFeeCategory);
                SuccessNotification("Fee Category created successfully.");
                if (continueEditing)
                {
                    return(RedirectToAction("Edit", new { id = objFeeCategory.Id }));
                }
            }
            else
            {
                model.AvailableAcadmicYears = _smsService.GetAllAcadmicYears().Select(x => new SelectListItem()
                {
                    Text     = x.Name.Trim(),
                    Value    = x.Id.ToString(),
                    Selected = model.AcadmicYearId > 0 ? model.AcadmicYearId == x.Id : false
                }).ToList();

                model.AvailableCategories = _smsService.GetAllCategories().Select(x => new SelectListItem()
                {
                    Text     = x.Name.Trim(),
                    Value    = x.Id.ToString(),
                    Selected = model.CategoryId > 0 && model.CategoryId == x.Id
                }).OrderBy(x => x.Text).ToList();

                model.AvailableClassDivisions = _smsService.GetAllClassRoomDivisions().Select(x => new SelectListItem()
                {
                    Text     = x.Class.Name.Trim() + " " + x.Division.Name,
                    Value    = x.Id.ToString(),
                    Selected = model.ClassDivisionId > 0 && model.ClassDivisionId == x.Id
                }).OrderBy(x => x.Text).ToList();
                return(View(model));
            }
            return(RedirectToAction("List"));
        }
示例#5
0
 public static FeeCategory ToEntity(this FeeCategoryModel model, FeeCategory destination)
 {
     return(model.MapTo(destination));
 }
示例#6
0
 public static FeeCategory ToEntity(this FeeCategoryModel model)
 {
     return(model.MapTo <FeeCategoryModel, FeeCategory>());
 }