public async Task <IActionResult> Index(string successMessage = "", string errorMessage = "")
        {
            if (!string.IsNullOrWhiteSpace(successMessage))
            {
                ViewData["SuccessMessage"] = successMessage;
            }
            else if (!string.IsNullOrWhiteSpace(errorMessage))
            {
                ViewData["ErrorMessage"] = errorMessage;
            }

            IndexViewModel _Model = new IndexViewModel
            {
                EmailSchedules = __Mapper.Map <IList <EmailScheduleViewModel> >(await __EmailScheduleManager.GetAsync()),
                Filter         = new EmailScheduleFilterViewModel
                {
                    EmailTemplatesSelectList = (await __EmailTemplateManager.GetAsync()).EmailTemplates.Select(x => new SelectListItem
                    {
                        Text  = x.Name,
                        Value = x.UID.ToString()
                    }).ToList()
                }
            };

            return(View(_Model));
        }
コード例 #2
0
        public async Task <IActionResult> ForceCompleteAsync(ForceCompleteLoanViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView(model));
            }

            LoanResponse _Loan = await __LoanManager.GetByUIDAsync(model.UID);

            if (_Loan == null)
            {
                return(Json(new { error = $"{GlobalConstants.ERROR_ACTION_PREFIX} find {ENTITY_NAME}." }));
            }

            if (DateTime.Now >= _Loan.ExpiryTimestamp)
            {
                await __LoanManager.ChangeStatusAsync(_Loan.UID, Status.Complete);
            }
            else
            {
                await __LoanManager.ChangeStatusAsync(_Loan.UID, Status.EarlyComplete);
            }

            await __LoanManager.CompleteLoanAsync(model.UID);

            foreach (LoanEquipmentResponse loanEquipment in await __LoanEquipmentManager.GetAsync(model.UID))
            {
                await __EquipmentManager.UpdateStatusAsync(loanEquipment.EquipmentUID, NsEquipmentEnum.Status.Available);
            }

            EmailScheduleResponse _Schedule = (await __EmailScheduleManager.GetAsync()).FirstOrDefault(s => s.Sent == false && s.RecipientEmailAddress == _Loan.LoaneeEmail && s.SendTimestamp == _Loan.ExpiryTimestamp);

            if (_Schedule != null)
            {
                await __EmailScheduleManager.UpdateSentAsync(_Schedule.UID, true);
            }

            return(Json(new { success = $"{GlobalConstants.SUCCESS_ACTION_PREFIX} completed {ENTITY_NAME}." }));
        }