コード例 #1
0
        public ActionResult Create()
        {
            if (!_permissionService.Authorize("ManageBook"))
            {
                return(AccessDeniedView());
            }

            var model = new BookIssueModel();

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

            model.AvailableEmployees = _smsService.GetAllEmployees().Select(x => new SelectListItem()
            {
                Text  = x.EmpFName.Trim() + (!string.IsNullOrEmpty(x.EmpMName) ? (" " + x.EmpMName) : "") + (!string.IsNullOrEmpty(x.EmpLName) ? (" " + x.EmpLName) : "") + ("(" + x.Username + ")"),
                Value = x.Id.ToString(),
            }).ToList();

            model.AvailableStudents = _smsService.GetAllStudents().Select(x => new SelectListItem()
            {
                Text  = x.FName.Trim() + (!string.IsNullOrEmpty(x.MName) ? (" " + x.MName) : "") + (!string.IsNullOrEmpty(x.LName) ? (" " + x.LName) : "") + ("(" + x.UserName + ")"),
                Value = x.Id.ToString(),
            }).ToList();
            return(View(model));
        }
コード例 #2
0
        public ActionResult Create(BookIssueModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize("ManageBook"))
            {
                return(AccessDeniedView());
            }

            var checkBookIssue = false;

            if (model.StudentId > 0 && model.BookId > 0)
            {
                // Check for duplicate classroom, if any
                checkBookIssue = _smsService.CheckBookIssueExists(model.StudentId, model.BookId, model.Id);
                if (checkBookIssue)
                {
                    ModelState.AddModelError("BookId", "Book already issued to student.");
                }
            }

            if (ModelState.IsValid)
            {
                var objBookIssue = model.ToEntity();
                objBookIssue.CreatedOn = objBookIssue.ModifiedOn = DateTime.Now;
                objBookIssue.UserId    = _userContext.CurrentUser.Id;
                objBookIssue.IssueDate = DateTime.Now;
                _smsService.InsertBookIssue(objBookIssue);
                SuccessNotification("Book issue record created successfully.");
                if (continueEditing)
                {
                    return(RedirectToAction("Edit", new { id = objBookIssue.Id }));
                }
            }
            else
            {
                model.AvailableBooks = _smsService.GetAllBooks().Select(x => new SelectListItem()
                {
                    Text     = x.Name.Trim(),
                    Value    = x.Id.ToString(),
                    Selected = model.BookId > 0 ? model.BookId == x.Id : false
                }).ToList();

                model.AvailableEmployees = _smsService.GetAllEmployees().Select(x => new SelectListItem()
                {
                    Text     = x.EmpFName.Trim() + (!string.IsNullOrEmpty(x.EmpMName) ? (" " + x.EmpMName) : "") + (!string.IsNullOrEmpty(x.EmpLName) ? (" " + x.EmpLName) : "") + ("(" + x.Username + ")"),
                    Value    = x.Id.ToString(),
                    Selected = model.LibrarianId > 0 ? model.LibrarianId == x.Id : false
                }).ToList();

                model.AvailableStudents = _smsService.GetAllStudents().Select(x => new SelectListItem()
                {
                    Text     = x.FName.Trim() + (!string.IsNullOrEmpty(x.MName) ? (" " + x.MName) : "") + (!string.IsNullOrEmpty(x.LName) ? (" " + x.LName) : "") + ("(" + x.UserName + ")"),
                    Value    = x.Id.ToString(),
                    Selected = model.StudentId > 0 ? model.StudentId == x.Id : false
                }).ToList();
                return(View(model));
            }
            return(RedirectToAction("List"));
        }
コード例 #3
0
        public ActionResult List()
        {
            if (!_permissionService.Authorize("ManageBook"))
            {
                return(AccessDeniedView());
            }

            var model = new BookIssueModel();

            return(View(model));
        }
コード例 #4
0
        public ActionResult Edit(int id)
        {
            if (!_permissionService.Authorize("ManageBook"))
            {
                return(AccessDeniedView());
            }

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

            var model        = new BookIssueModel();
            var objBookIssue = _smsService.GetBookIssueById(id);

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

            model.AvailableBooks = _smsService.GetAllBooks().Select(x => new SelectListItem()
            {
                Text     = x.Name.Trim(),
                Value    = x.Id.ToString(),
                Selected = model.BookId == x.Id
            }).ToList();

            model.AvailableEmployees = _smsService.GetAllEmployees().Select(x => new SelectListItem()
            {
                Text     = x.EmpFName.Trim() + (!string.IsNullOrEmpty(x.EmpMName) ? (" " + x.EmpMName) : "") + (!string.IsNullOrEmpty(x.EmpLName) ? (" " + x.EmpLName) : "") + ("(" + x.Username + ")"),
                Value    = x.Id.ToString(),
                Selected = model.LibrarianId == x.Id
            }).ToList();

            model.AvailableStudents = _smsService.GetAllStudents().Select(x => new SelectListItem()
            {
                Text     = x.FName.Trim() + (!string.IsNullOrEmpty(x.MName) ? (" " + x.MName) : "") + (!string.IsNullOrEmpty(x.LName) ? (" " + x.LName) : "") + ("(" + x.UserName + ")"),
                Value    = x.Id.ToString(),
                Selected = model.StudentId == x.Id
            }).ToList();
            return(View(model));
        }
コード例 #5
0
 public async Task <IActionResult> Index(BookIssueModel bookIssueModel)
 {
     return(View());
 }
コード例 #6
0
 public static BookIssue ToEntity(this BookIssueModel model, BookIssue destination)
 {
     return(model.MapTo(destination));
 }
コード例 #7
0
 public static BookIssue ToEntity(this BookIssueModel model)
 {
     return(model.MapTo <BookIssueModel, BookIssue>());
 }