Exemplo n.º 1
0
 public BorrowDto MapBorrowDto(BorrowViewModel borrowViewModel)
 {
     if (borrowViewModel == null)
     {
         return null;
     }
     var borrowDto = new BorrowDto()
     {
         Id = borrowViewModel.Id,
         RequestDate = borrowViewModel.RequestDate,
         LoanDate = borrowViewModel.LoanDate,
         ReturnDate = borrowViewModel.ReturnDate,
         ItemId = borrowViewModel.ItemId,
         PersonId = borrowViewModel.PersonId
     };
     return borrowDto;
 }
Exemplo n.º 2
0
 public BorrowViewModel MapBorrowViewModel(BorrowDto borrowDto)
 {
     if (borrowDto == null)
     {
         return null;
     }
     var borrow = new BorrowViewModel()
     {
         Id = borrowDto.Id,
         RequestDate = borrowDto.RequestDate,
         LoanDate = borrowDto.LoanDate,
         ReturnDate = borrowDto.ReturnDate,
         ItemId = borrowDto.ItemId,
         PersonId = borrowDto.PersonId,
         PersonName = borrowDto.Person.PersonName,
         PersonSurname = borrowDto.Person.Surname,
         ItemName =  borrowDto.Item.ItemName
     };
     return borrow;
 }
Exemplo n.º 3
0
 // GET: Borrow/Create
 public ActionResult Create()
 {
     var borrowViewModel = new BorrowViewModel();
     SetBorrowViewModelSelectListItems(borrowViewModel);
     return View(borrowViewModel);
 }
Exemplo n.º 4
0
        public ActionResult Create(BorrowViewModel borrowViewModel)
        {
            if (borrowViewModel.PersonId == 0)
                ModelState.AddModelError("PersonFieldCannotBeNull", "Please Select a Person");
            if (borrowViewModel.ItemId == 0)
                ModelState.AddModelError("ItemFieldCannotBeNull", "Please Select an Item");
            if (IsItemOnLoan(borrowViewModel.ItemId))
            {
                ModelState.AddModelError("ItemCannotBeBorrowed", "Sorry item is currently on loan.");
            }

            if (!ModelState.IsValid)
            {
                SetBorrowViewModelSelectListItems(borrowViewModel);
                return View(borrowViewModel);
            }
            var mapper = new BorrowMapper();
           
            var borrowDto = mapper.MapBorrowDto(borrowViewModel);
            _borrowRepository.Add(borrowDto);

            return RedirectToAction("Index");
        }
Exemplo n.º 5
0
        private void SetBorrowViewModelSelectListItems(BorrowViewModel borrowViewModel)
        {
            var peopleList = new List<SelectListItem>
            {
                new SelectListItem {Text = "Select Person Below", Value = "0" }
            };
            peopleList.AddRange(GetPeopleSelectList());
            borrowViewModel.PeopleSelectList = peopleList;

            var itemsList = new List<SelectListItem>
            {
                new SelectListItem { Text = "Select an Item Below", Value = "0" }
            };
            itemsList.AddRange(GetItemsSelectList());
            borrowViewModel.ItemsSelectList = itemsList;
        }