示例#1
0
        public async Task <IActionResult> CreateViewAsync()
        {
            IList <LoanResponse> _Loans = (await __LoanManager.GetAsync()).Where(loan => loan.Status != Status.Complete && loan.Status != Enums.Loan.Status.EarlyComplete).ToList();

            CreateLoanViewModel _Model = new CreateLoanViewModel
            {
                EquipmentSelectList = __Mapper.Map <IList <Equipment.Models.EquipmentViewModel> >((await __EquipmentManager.GetAsync()).Where(x => x.Status == NsEquipmentEnum.Status.Available)),
                UserSelectList      = await __UserRepository.GetAsync(),
                Blacklists          = __Mapper.Map <IList <Admin.Models.Blacklist.BlacklistViewModel> >(await __BlacklistManager.GetAsync()),
            };

            return(View("CreateLoan", _Model));
        }
示例#2
0
        public async Task <IActionResult> CreateAsync(ConfirmationLoanViewModel model)
        {
            if (!ModelState.IsValid)
            {
                if (model.ExpiryTimestamp <= model.FromTimestamp)
                {
                    ModelState.AddModelError("Error", "Schedule From field must be less than Schedule To");
                    return(View("CreateLoan", model));
                }

                IList <LoanResponse> _Loans            = (await __LoanManager.GetAsync()).Where(loan => loan.Status != Enums.Loan.Status.Complete && loan.Status != Enums.Loan.Status.EarlyComplete).ToList();
                List <Guid>          _ExcludeEquipment = new List <Guid>();
                foreach (LoanResponse loan in _Loans)
                {
                    IList <LoanEquipmentResponse> _LoanEquipment = await __LoanEquipmentManager.GetAsync(loan.UID);

                    _ExcludeEquipment.AddRange(_LoanEquipment.Select(x => x.EquipmentUID));
                }
                _ExcludeEquipment = _ExcludeEquipment.Distinct().ToList();

                CreateLoanViewModel _CreateLoanViewModel = new CreateLoanViewModel
                {
                    EquipmentSelectList = __Mapper.Map <IList <Equipment.Models.EquipmentViewModel> >((await __EquipmentManager.GetAsync()).Where(x => x.Status == NsEquipmentEnum.Status.Available && !_ExcludeEquipment.Contains(x.UID))),
                    UserSelectList      = await __UserRepository.GetAsync(),
                    Blacklists          = __Mapper.Map <IList <Admin.Models.Blacklist.BlacklistViewModel> >(await __BlacklistManager.GetAsync())
                };

                ModelState.AddModelError("Error", "Unable to create Loan");
                return(View("CreateLoan", _CreateLoanViewModel));
            }

            model.LoanerEmail = __UserManager.GetUserAsync(HttpContext.User).Result.Email;
            LoanResponse _Response = await __LoanManager.CreateAsync(__Mapper.Map <CreateLoanRequest>(model));

            if (!_Response.Success)
            {
                ModelState.AddModelError("Error", _Response.Message);
                return(View("CreateLoan", model));
            }

            LoanResponse _LoanResponse = await __LoanManager.GetByUIDAsync(_Response.UID);

            await __EmailScheduleManager.CreateLoanConfirmScheduleAsync(_LoanResponse, $"{this.Request.Scheme}://{this.Request.Host}{this.Request.PathBase}", true);

            return(RedirectToAction("Index", "Loan", new { Area = "Loan", successMessage = $"{GlobalConstants.SUCCESS_ACTION_PREFIX} created {ENTITY_NAME}." }));
        }
        public async Task <IActionResult> CreateLoan(CreateLoanViewModel vm)
        {
            string userId      = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var    clientCheck = await _loanService.AddClient(vm.ClientName, vm.ClientPhoneNumber, vm.ClientEGN, vm.ClientEmail, userId);

            try
            {
                await _loanService.CreateLoanApplication(clientCheck, vm.LoanSum, userId, vm.EmailDbId);
            }
            catch (LoanExeptions ex)
            {
                log.Error($"Failed to create loan application. |{ex}| error");
                return(RedirectToAction("ListAllStatusEmails", "Email"));
            }

            return(RedirectToAction("ListAllStatusEmails", "Email"));
        }
示例#4
0
        public async Task <IActionResult> ConfirmViewAsync(CreateLoanViewModel model)
        {
            if (model.ExpiryTimestamp <= model.FromTimestamp)
            {
                ModelState.AddModelError("Error", "Schedule From field must be less than Schedule To");
                return(View("CreateLoan", model));
            }

            if (!ModelState.IsValid)
            {
                IList <LoanResponse> _Loans            = (await __LoanManager.GetAsync()).Where(loan => loan.Status != Enums.Loan.Status.Complete && loan.Status != Enums.Loan.Status.EarlyComplete).ToList();
                List <Guid>          _ExcludeEquipment = new List <Guid>();
                foreach (LoanResponse loan in _Loans)
                {
                    IList <LoanEquipmentResponse> _Response = await __LoanEquipmentManager.GetAsync(loan.UID);

                    _ExcludeEquipment.AddRange(_Response.Select(x => x.EquipmentUID));
                }
                _ExcludeEquipment = _ExcludeEquipment.Distinct().ToList();

                model.EquipmentSelectList = __Mapper.Map <IList <Equipment.Models.EquipmentViewModel> >((await __EquipmentManager.GetAsync()).Where(x => x.Status == NsEquipmentEnum.Status.Available && !_ExcludeEquipment.Contains(x.UID)));
                model.UserSelectList      = await __UserRepository.GetAsync();

                model.Blacklists = __Mapper.Map <IList <Admin.Models.Blacklist.BlacklistViewModel> >(await __BlacklistManager.GetAsync());

                return(View("CreateLoan", model));
            }

            ConfirmationLoanViewModel _Model = new ConfirmationLoanViewModel
            {
                ExpiryTimestamp       = model.ExpiryTimestamp,
                FromTimestamp         = model.FromTimestamp,
                LoaneeEmail           = model.LoaneeEmailAddress,
                SelectedEquipmentList = __Mapper.Map <IList <Equipment.Models.EquipmentViewModel> >((await __EquipmentManager.GetAsync(model.SelectedEquipment)).Equipments),
                LoanerEmail           = __UserManager.GetUserAsync(HttpContext.User).Result.Email,
                BlacklistState        = await __BlacklistManager.GetState(model.LoaneeEmailAddress)
            };

            return(View("ConfirmationLoan", _Model));
        }
示例#5
0
 public IActionResult CreateLoan(CreateLoanViewModel model)
 {
     model.Loan = _loanLogic.CreateLoan(model.Card_ID, model.Barcode1, model.Barcode2, model.Barcode3, model.Barcode4, model.Barcode5, 1);
     return(View("Create", model));
 }
示例#6
0
        public ActionResult CreateLoan(CreateLoanViewModel vm)
        {
            if (vm.SelectedHourFromId < 0)
            {
                ModelState.AddModelError("TimeFrom", Loan.Validator.TIME_FROM_REQUIRED);
            }
            if (vm.SelectedHourToId < 0)
            {
                ModelState.AddModelError("TimeTo", Loan.Validator.TIME_TO_REQUIRED);
            }

            var timeFrom = vm.DateFrom.AddHours(vm.SelectedHourFromId);
            var timeTo   = vm.DateTo.AddHours(vm.SelectedHourToId);

            var timeFromValidation = Loan.Validator.ValidateTimeTo(timeFrom);

            if (timeFromValidation != null)
            {
                ModelState.AddModelError("TimeFrom", timeFromValidation);
            }

            var timeToValidation = Loan.Validator.ValidateTimeTo(timeTo);

            if (timeToValidation != null)
            {
                ModelState.AddModelError("TimeTo", timeFromValidation);
            }

            var intervalValidation = Loan.Validator.ValidateTimeInterval(timeFrom, timeTo);

            if (intervalValidation != null)
            {
                ModelState.AddModelError("TimeFrom", intervalValidation);
                ModelState.AddModelError("TimeTo", intervalValidation);
            }

            var availableValidation = Loan.Validator.ValidateAssetAvailabilty(vm.AssetId, timeFrom, timeTo);

            if (availableValidation != null)
            {
                ModelState.AddModelError("", availableValidation);
            }

            var roomValidation = Loan.Validator.ValidateRoom(vm.SelectedRoomId);

            if (roomValidation != null)
            {
                ModelState.AddModelError("SelectedRoomId", roomValidation);
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var loan = new Loan
                    {
                        AssetId  = vm.AssetId,
                        RoomId   = vm.SelectedRoomId,
                        TimeFrom = timeFrom,
                        TimeTo   = timeTo,
                        UserId   = User.Identity.GetUserId(),
                    };
                    db.Loans.Add(loan);
                    db.SaveChanges();

                    return(Json(new { Success = true, Message = Loan.SAVE_SUCCESS }));
                }
                catch (Exception e)
                {
                    return(Json(new { Success = false, Message = Loan.SAVE_FAIL }));
                }
            }

            vm.Hours = GenerateHours();
            vm.Rooms = db.RoomDropdown();
            return(PartialView("_CreateLoan", vm));
        }