コード例 #1
0
        public ActionResult UpdateCheckout(MedicalCheckoutInfo medicalCheckoutInfo)
        {
            try
            {
                int _id;
                MedicalCheckoutInfo _medicalCheckout = null;

                if (!ModelState.IsValid)
                {
                    TempData["Msg"] = AlertMessageProvider.FailureMessage("Invalid data.");

                    return(RedirectToAction("Details", "Medical"));
                }

                if (!int.TryParse(medicalCheckoutInfo.Id.ToString(), out _id))
                {
                    return(RedirectToAction("Details", "Medical"));
                }

                using (FamilyMemberRepository Repo = new FamilyMemberRepository())
                {
                    FamilyMemberInfo _familyMember = null;

                    _familyMember = Repo.GetFamilyMemberById(medicalCheckoutInfo.FamilyMemberId);

                    if (_familyMember == null || _familyMember.EmployeeInfoId != CurrentUser.EmployeeInfoId)
                    {
                        TempData["Msg"] = AlertMessageProvider.FailureMessage("Invalid patient name.");

                        return(RedirectToAction("Details", "Medical"));
                    }
                }

                using (MedicalCheckoutRepository Repo = new MedicalCheckoutRepository())
                {
                    _medicalCheckout = Repo.GetMedicalCheckoutById(_id);

                    if (_medicalCheckout == null || _medicalCheckout.EmployeeInfoId != CurrentUser.EmployeeInfoId || _medicalCheckout.Status == "Approved")
                    {
                        TempData["Msg"] = AlertMessageProvider.FailureMessage("Checkout not found.");

                        return(RedirectToAction("Details", "Medical"));
                    }

                    Repo.UpdateMedicalCheckout(medicalCheckoutInfo);
                }

                return(RedirectToAction("Apply", "Medical", new { id = medicalCheckoutInfo.Id }));
            }

            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Medical", "UpdateCheckout")));
            }
        }
コード例 #2
0
        public ActionResult ApplyMedical(string id = "")
        {
            try
            {
                int _id;
                MedicalCheckoutInfo _medicalCheckout = null;

                if (!int.TryParse(id, out _id))
                {
                    TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong please try again later.");

                    return(RedirectToAction("Details", "Medical"));
                }

                using (MedicalPrescriptionRepository Repo = new MedicalPrescriptionRepository())
                {
                    var _prescriptions = Repo.GetMedicalPrescriptionsListByMedicalCheckoutId(_id);

                    if (_prescriptions.Count() == 0)
                    {
                        TempData["Msg"] = AlertMessageProvider.FailureMessage("Please upload prescription(s).");

                        return(RedirectToAction("Details", "Medical", new { id = _id }));
                    }
                }

                using (MedicalCheckoutRepository Repo = new MedicalCheckoutRepository())
                {
                    _medicalCheckout = Repo.GetMedicalCheckoutById(_id);

                    if (_medicalCheckout == null || _medicalCheckout.EmployeeInfoId != CurrentUser.EmployeeInfoId || _medicalCheckout.Status == "Approved")
                    {
                        TempData["Msg"] = AlertMessageProvider.FailureMessage("Checkout not found.");

                        return(RedirectToAction("Details", "Medical"));
                    }

                    _medicalCheckout.RequestDate      = DateTime.Now;
                    _medicalCheckout.IsCreatedByAdmin = false;
                    _medicalCheckout.Status           = "Pending";

                    Repo.UpdateMedicalCheckout(_medicalCheckout);

                    TempData["Msg"] = AlertMessageProvider.SuccessMessage("You have applied for medical successfully.");
                }

                return(RedirectToAction("Details", "Medical"));
            }

            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Medical", "ApplyMedical")));
            }
        }
コード例 #3
0
        public ActionResult CancelCheckout(string CheckoutId)
        {
            try
            {
                int id;
                MedicalCheckoutInfo _checkout = null;
                var _prescriptionsList        = new List <MedicalPrescriptionInfo>();

                if (!int.TryParse(CheckoutId, out id))
                {
                    TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later.");

                    return(RedirectToAction("Details", "Medical"));
                }

                using (MedicalCheckoutRepository Repo = new MedicalCheckoutRepository())
                {
                    _checkout = Repo.GetMedicalCheckoutById(id);

                    if (_checkout == null || _checkout.EmployeeInfoId != CurrentUser.EmployeeInfoId || _checkout.Status == "Approved")
                    {
                        TempData["Msg"] = AlertMessageProvider.FailureMessage("Checkout not found.");

                        return(RedirectToAction("Details", "Medical"));
                    }

                    _checkout.Status = "Incomplete";

                    Repo.UpdateMedicalCheckout(_checkout);
                }

                TempData["Msg"] = AlertMessageProvider.SuccessMessage("Checkout canceled successfully.");

                return(RedirectToAction("Details", "Medical"));
            }

            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Medical", "CancelCheckout")));
            }
        }
コード例 #4
0
        public ActionResult ProcessRequest(string CheckoutId = "", string ProcessBtn = "")
        {
            try
            {
                int _id;
                MedicalCheckoutInfo  _checkout         = null;
                EmployeeInfo         _employeeInfo     = null;
                MedicalAllowanceInfo _medicalAllowance = null;

                if (!int.TryParse(CheckoutId, out _id))
                {
                    TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later.");

                    return(RedirectToAction("Requests", "Medical"));
                }

                using (MedicalCheckoutRepository CheckoutRepo = new MedicalCheckoutRepository())
                {
                    _checkout = CheckoutRepo.GetMedicalCheckoutById(_id);

                    if (_checkout == null)
                    {
                        TempData["Msg"] = AlertMessageProvider.FailureMessage("Checkout not found.");

                        return(RedirectToAction("Requests", "Medical"));
                    }

                    if (ProcessBtn != "Approve" && ProcessBtn != "Reject")
                    {
                        TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later.");

                        return(RedirectToAction("RequestDetails", "Medical", new { id = _checkout.Id }));
                    }

                    if (ProcessBtn == "Approve")
                    {
                        using (EmployeeRepository EmployeeRepo = new EmployeeRepository())
                        {
                            _employeeInfo = EmployeeRepo.GetEmployeeInfoById(_checkout.EmployeeInfoId);
                        }

                        using (MedicalAllowanceRepository AllowanceRepo = new MedicalAllowanceRepository())
                        {
                            if (_employeeInfo.MaritalStatus == "Single")
                            {
                                _medicalAllowance = AllowanceRepo.GetMedicalAllowanceByCategory("Single");
                            }
                            else
                            {
                                _medicalAllowance = AllowanceRepo.GetMedicalAllowanceByCategory("Married");
                            }
                        }

                        var _availedMedical = CheckoutRepo.GetAvailedMedicalCheckoutsListByEmployeeIdYearwise(_checkout.EmployeeInfoId, DateTime.Now.ToString("yyyy"));

                        var remainingMedicalAmount = _medicalAllowance.Amount - _availedMedical.Sum(x => x.Amount);

                        if (_checkout.Amount > remainingMedicalAmount)
                        {
                            TempData["Msg"] = AlertMessageProvider.FailureMessage("This request cannot be process, employee has insufficient medical amount.");

                            return(RedirectToAction("RequestDetails", "Medical", new { id = _checkout.EmployeeInfoId }));
                        }

                        _checkout.Status = "Approved";

                        TempData["Msg"] = AlertMessageProvider.SuccessMessage("Medical request approved successfully.");
                    }
                    else
                    {
                        _checkout.Status = "Incomplete";

                        TempData["Msg"] = AlertMessageProvider.SuccessMessage("Medical request rejected successfully.");
                    }

                    CheckoutRepo.UpdateMedicalCheckout(_checkout);
                }

                return(RedirectToAction("RequestDetails", "Medical", new { id = _checkout.EmployeeInfoId }));
            }

            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Medical", "ProcessRequest")));
            }
        }