public int SaveMedicalCheckout(MedicalCheckoutInfo medicalCheckoutInfo)
        {
            Data.MedicalCheckout medicalCheckout = ConvertToDb(medicalCheckoutInfo);

            _context.MedicalCheckouts.Add(medicalCheckout);
            _context.SaveChanges();

            return(medicalCheckout.Id);
        }
Example #2
0
        public ActionResult DownloadPrescriptions(string CheckoutId = "")
        {
            try
            {
                int id;
                var _prescriptionsList        = new List <MedicalPrescriptionInfo>();
                MedicalCheckoutInfo _checkout = null;
                var outputStream = new MemoryStream();

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

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

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

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

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

                var _zipName = _checkout.PatientName + "_Prescriptions_" + _checkout.TreatmentDate.Value.ToString("dd-MM-yyyy");

                using (MedicalPrescriptionRepository PrescriptionRepo = new MedicalPrescriptionRepository())
                {
                    _prescriptionsList = PrescriptionRepo.GetMedicalPrescriptionsListByMedicalCheckoutId(id);

                    using (var zip = new ZipFile())
                    {
                        foreach (var item in _prescriptionsList)
                        {
                            zip.AddFile(Server.MapPath(item.PrescriptionPath), string.Empty).FileName = item.FileName;
                        }

                        zip.Save(outputStream);
                    }
                }

                outputStream.Position = 0;

                return(File(outputStream, "application/zip", _zipName));
            }

            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Medical", "DownloadPrescriptions")));
            }
        }
Example #3
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")));
            }
        }
Example #4
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")));
            }
        }
Example #5
0
        // GET: Admin/Medical/Manage
        public ActionResult Manage(string id = "")
        {
            try
            {
                ViewBag.EmployeeId = GetEmployeeFullNameList();

                int    empId;
                var    _checkout     = new MedicalCheckoutInfo();
                var    _employeeInfo = new EmployeeInfo();
                string _medicalYear  = DateTime.Now.Year.ToString();

                if (!int.TryParse(id, out empId))
                {
                    _checkout = null;

                    return(View(_checkout));
                }

                using (MedicalCheckoutRepository Repo = new MedicalCheckoutRepository())
                {
                    ViewBag.MedicalYear = new SelectList(Repo.GetMedicalYearsList(empId));

                    _checkout.AvailedMedicalsList = Repo.GetAvailedMedicalCheckoutsListByEmployeeIdYearwise(empId, _medicalYear);
                }

                using (EmployeeRepository Repo = new EmployeeRepository())
                {
                    _employeeInfo = Repo.GetEmployeeInfoById(empId);
                }

                using (MedicalAllowanceRepository Repo = new MedicalAllowanceRepository())
                {
                    if (_employeeInfo.MaritalStatus == "Single")
                    {
                        _checkout.MedicalAllowance = Repo.GetMedicalAllowanceByCategory("Single");
                    }
                    else
                    {
                        _checkout.MedicalAllowance = Repo.GetMedicalAllowanceByCategory("Married");
                    }
                }

                _checkout.EmployeeInfoId = int.Parse(id);

                return(View(_checkout));
            }

            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Medical", "Manage")));
            }
        }
Example #6
0
        public ActionResult Manage(string MedicalYear = "", string id = "")
        {
            try
            {
                ViewBag.EmployeeId = GetEmployeeFullNameList();

                int _id;
                int _medicalYear;
                var _medicalCheckout = new MedicalCheckoutInfo();
                _medicalCheckout.AvailedMedicalsList = new List <MedicalCheckoutInfo>();

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

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

                if (MedicalYear == DateTime.Now.ToString("yyyy"))
                {
                    return(RedirectToAction("Manage", "Medical"));
                }

                using (MedicalCheckoutRepository Repo = new MedicalCheckoutRepository())
                {
                    ViewBag.MedicalYear = new SelectList(Repo.GetMedicalYearsList(_id));
                    _medicalCheckout.AvailedMedicalsList = Repo.GetAvailedMedicalCheckoutsListByEmployeeIdYearwise(_id, MedicalYear);
                }

                if (_medicalCheckout.AvailedMedicalsList.Count() == 0)
                {
                    TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later.");

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

                _medicalCheckout.EmployeeInfoId   = _id;
                _medicalCheckout.MedicalAllowance = null;

                return(View(_medicalCheckout));
            }

            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Medical", "Manage")));
            }
        }
 public Data.MedicalCheckout ConvertToDb(MedicalCheckoutInfo medicalCheckoutInfo)
 {
     return(new Data.MedicalCheckout
     {
         Id = medicalCheckoutInfo.Id,
         RequestDate = medicalCheckoutInfo.RequestDate,
         TreatmentDate = medicalCheckoutInfo.TreatmentDate,
         Description = medicalCheckoutInfo.Description,
         Amount = medicalCheckoutInfo.Amount,
         Status = medicalCheckoutInfo.Status,
         IsCreatedByAdmin = medicalCheckoutInfo.IsCreatedByAdmin,
         RequestProcessDate = medicalCheckoutInfo.RequestProcessDate,
         RequestProcessByAccountId = medicalCheckoutInfo.RequestProcessByAccountId,
         EmployeeInfoId = medicalCheckoutInfo.EmployeeInfoId,
         FamilyMemberId = medicalCheckoutInfo.FamilyMemberId
     });
 }
Example #8
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")));
            }
        }
Example #9
0
        public ActionResult Details(string MedicalYear = "")
        {
            try
            {
                var _medicalCheckout = new MedicalCheckoutInfo();
                _medicalCheckout.AvailedMedicalsList = new List <MedicalCheckoutInfo>();

                if (MedicalYear == DateTime.Now.ToString("yyyy"))
                {
                    return(RedirectToAction("Details", "Medical"));
                }

                using (FamilyMemberRepository Repo = new FamilyMemberRepository())
                {
                    TempData["FamilyMembersList"] = new SelectList(Repo.GetAllFamilyMembersListByEmployeeId(CurrentUser.EmployeeInfoId), "Id", "Name");
                }

                using (MedicalCheckoutRepository Repo = new MedicalCheckoutRepository())
                {
                    ViewBag.MedicalYear = new SelectList(Repo.GetMedicalYearsList(CurrentUser.EmployeeInfoId));
                    _medicalCheckout.AvailedMedicalsList = Repo.GetAvailedMedicalCheckoutsListByEmployeeIdYearwise(CurrentUser.EmployeeInfoId, MedicalYear);
                }

                if (_medicalCheckout.AvailedMedicalsList.Count() == 0)
                {
                    TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later.");

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

                _medicalCheckout.MedicalAllowance = null;

                return(View(_medicalCheckout));
            }

            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Medical", "Details")));
            }
        }
Example #10
0
        // GET: Employee/Medical/Apply
        public ActionResult Apply(string id = "")
        {
            try
            {
                int _id;
                MedicalCheckoutInfo _medicalCheckout = null;

                if (!int.TryParse(id, out _id))
                {
                    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"));
                }

                using (MedicalPrescriptionRepository Repo = new MedicalPrescriptionRepository())
                {
                    _medicalCheckout.MedicalPrescriptions = new List <MedicalPrescriptionInfo>();

                    _medicalCheckout.MedicalPrescriptions = Repo.GetMedicalPrescriptionsListByMedicalCheckoutId(_id);
                }

                return(View(_medicalCheckout));
            }

            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Medical", "Apply")));
            }
        }
        public void UpdateMedicalCheckout(MedicalCheckoutInfo medicalCheckoutInfo)
        {
            Data.MedicalCheckout medicalCheckout = _context.MedicalCheckouts.Find(medicalCheckoutInfo.Id);

            if (medicalCheckout != null)
            {
                medicalCheckout.RequestDate               = medicalCheckoutInfo.RequestDate;
                medicalCheckout.TreatmentDate             = medicalCheckoutInfo.TreatmentDate;
                medicalCheckout.Description               = medicalCheckoutInfo.Description;
                medicalCheckout.Amount                    = medicalCheckoutInfo.Amount;
                medicalCheckout.Status                    = medicalCheckoutInfo.Status;
                medicalCheckout.IsCreatedByAdmin          = medicalCheckoutInfo.IsCreatedByAdmin;
                medicalCheckout.RequestProcessDate        = medicalCheckoutInfo.RequestProcessDate;
                medicalCheckout.RequestProcessByAccountId = medicalCheckoutInfo.RequestProcessByAccountId;
                medicalCheckout.FamilyMemberId            = medicalCheckoutInfo.FamilyMemberId;

                _context.SaveChanges();
            }
            else
            {
                throw new ArgumentNullException();
            }
        }
Example #12
0
        // GET: Employee/Medical/UpdateCheckout
        public ActionResult UpdateCheckout(string id = "")
        {
            try
            {
                int _id;
                MedicalCheckoutInfo _medicalCheckout = null;

                if (!int.TryParse(id, out _id))
                {
                    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"));
                }

                using (FamilyMemberRepository Repo = new FamilyMemberRepository())
                {
                    TempData["FamilyMembersList"] = new SelectList(Repo.GetAllFamilyMembersListByEmployeeId(CurrentUser.EmployeeInfoId), "Id", "Name");
                }

                return(View(_medicalCheckout));
            }

            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Medical", "UpdateCheckout")));
            }
        }
Example #13
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")));
            }
        }
Example #14
0
        public ActionResult UploadPrescription(HttpPostedFileBase file, MedicalCheckoutInfo medicalCheckoutInfo)
        {
            try
            {
                int id;
                MedicalCheckoutInfo _medicalCheckout = null;
                var _prescription = new MedicalPrescriptionInfo();

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

                    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"));
                }

                if (string.IsNullOrEmpty(medicalCheckoutInfo.PrescriptionName))
                {
                    TempData["Msg"] = AlertMessageProvider.FailureMessage("Prescription name is required.");

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

                if (file != null)
                {
                    if (file.ContentType.Contains("image"))
                    {
                        if (file.ContentLength < 2 * 1024 * 1024)
                        {
                            if (file.FileName.Contains(".jpeg") || file.FileName.Contains(".jpg"))
                            {
                                _prescription.FileName          = medicalCheckoutInfo.PrescriptionName + Path.GetExtension(file.FileName);
                                _prescription.UploadDate        = DateTime.Now;
                                _prescription.MedicalCheckoutId = medicalCheckoutInfo.Id;

                                string _dirPath = Server.MapPath(Url.Content("~/Content/Employee_medical_documents/" + _medicalCheckout.EmployeeName + _medicalCheckout.EmployeeInfoId + " Prescriptions"));

                                bool _isDirectoryExists = System.IO.Directory.Exists(_dirPath);

                                if (!_isDirectoryExists)
                                {
                                    System.IO.Directory.CreateDirectory(Server.MapPath(Url.Content("~/Content/Employee_medical_documents/" + _medicalCheckout.EmployeeName + _medicalCheckout.EmployeeInfoId + " Prescriptions")));
                                }

                                Guid guid = Guid.NewGuid();
                                _prescription.PrescriptionPath = Url.Content("~/Content/Employee_medical_documents/" + _medicalCheckout.EmployeeName + _medicalCheckout.EmployeeInfoId + " Prescriptions/" + _medicalCheckout.EmployeeInfoId + "-" + guid + "-" + _prescription.FileName);

                                string _prescriptionPath = Server.MapPath(_prescription.PrescriptionPath);

                                using (MedicalPrescriptionRepository Repo = new MedicalPrescriptionRepository())
                                {
                                    file.SaveAs(_prescriptionPath);

                                    Repo.SaveMedicalPrescription(_prescription);
                                }
                            }
                            else
                            {
                                TempData["Msg"] = AlertMessageProvider.FailureMessage("Please select 'jpeg, jpg' format only.");

                                return(RedirectToAction("Apply", "Medical", new { id = _medicalCheckout.Id }));
                            }
                        }
                        else
                        {
                            TempData["Msg"] = AlertMessageProvider.FailureMessage("Please select size upto 2 MB or smaller.");

                            return(RedirectToAction("Apply", "Medical", new { id = _medicalCheckout.Id }));
                        }
                    }
                    else
                    {
                        TempData["Msg"] = AlertMessageProvider.FailureMessage("Invalid content type, please select image only.");

                        return(RedirectToAction("Apply", "Medical", new { id = _medicalCheckout.Id }));
                    }
                }
                else
                {
                    TempData["Msg"] = AlertMessageProvider.FailureMessage("Please select prescription.");

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

                TempData["Msg"] = AlertMessageProvider.SuccessMessage("Prescription uploaded successfully.");

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

            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Medical", "UploadPrescription")));
            }
        }
Example #15
0
        // GET: Employee/Medical/Details
        public ActionResult Details()
        {
            try
            {
                var _employeeInfo    = new EmployeeInfo();
                var _medicalCheckout = new MedicalCheckoutInfo();
                _medicalCheckout.AvailedMedicalsList = new List <MedicalCheckoutInfo>();
                _medicalCheckout.PendingMedicalsList = new List <MedicalCheckoutInfo>();
                _medicalCheckout.MedicalAllowance    = new MedicalAllowanceInfo();
                var    _incompleteMedicalChekouts = new List <MedicalCheckoutInfo>();
                string _medicalYear = DateTime.Now.Year.ToString();

                using (FamilyMemberRepository Repo = new FamilyMemberRepository())
                {
                    TempData["FamilyMembersList"] = new SelectList(Repo.GetAllFamilyMembersListByEmployeeId(CurrentUser.EmployeeInfoId), "Id", "Name");
                }

                using (var transaction = new System.Transactions.TransactionScope())
                {
                    using (MedicalCheckoutRepository Repo = new MedicalCheckoutRepository())
                    {
                        ViewBag.MedicalYear = new SelectList(Repo.GetMedicalYearsList(CurrentUser.EmployeeInfoId));

                        _incompleteMedicalChekouts = Repo.GetIncompleteMedicalCheckoutsListByEmployeeId(CurrentUser.EmployeeInfoId);

                        if (_incompleteMedicalChekouts.Count() > 0)
                        {
                            using (MedicalPrescriptionRepository PrescriptionRepo = new MedicalPrescriptionRepository())
                            {
                                foreach (var checkout in _incompleteMedicalChekouts)
                                {
                                    var _prescriptionsList = PrescriptionRepo.GetMedicalPrescriptionsListByMedicalCheckoutId(checkout.Id);

                                    foreach (var prescription in _prescriptionsList)
                                    {
                                        string fullPath = Request.MapPath(prescription.PrescriptionPath);

                                        if (System.IO.File.Exists(fullPath))
                                        {
                                            System.IO.File.Delete(fullPath);
                                        }

                                        PrescriptionRepo.DeleteMedicalPrescription(prescription.Id);
                                    }

                                    Repo.DeleteMedicalCheckout(checkout.Id);
                                }
                            }
                        }

                        _medicalCheckout.PendingMedicalsList = Repo.GetPendingMedicalCheckoutsListByEmployeeId(CurrentUser.EmployeeInfoId);
                        _medicalCheckout.AvailedMedicalsList = Repo.GetAvailedMedicalCheckoutsListByEmployeeIdYearwise(CurrentUser.EmployeeInfoId, _medicalYear);
                    }

                    transaction.Complete();
                }

                using (EmployeeRepository Repo = new EmployeeRepository())
                {
                    _employeeInfo = Repo.GetEmployeeInfoById(CurrentUser.EmployeeInfoId);
                }

                using (MedicalAllowanceRepository Repo = new MedicalAllowanceRepository())
                {
                    if (_employeeInfo.MaritalStatus == "Single")
                    {
                        _medicalCheckout.MedicalAllowance = Repo.GetMedicalAllowanceByCategory("Single");
                    }
                    else
                    {
                        _medicalCheckout.MedicalAllowance = Repo.GetMedicalAllowanceByCategory("Married");
                    }
                }

                return(View(_medicalCheckout));
            }

            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Medical", "Details")));
            }
        }
Example #16
0
        public ActionResult SaveCheckout(MedicalCheckoutInfo medicalCheckoutInfo)
        {
            try
            {
                int                  _medicalCheckoutId = 0;
                EmployeeInfo         _employeeInfo      = null;
                MedicalAllowanceInfo _medicalAllowance  = null;

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

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

                if (medicalCheckoutInfo.TreatmentDate > DateTime.Now.Date)
                {
                    TempData["Msg"] = AlertMessageProvider.FailureMessage("Treatment date cannot be earlier than today.");

                    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 (EmployeeRepository Repo = new EmployeeRepository())
                {
                    _employeeInfo = Repo.GetEmployeeInfoById(CurrentUser.EmployeeInfoId);
                }

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

                using (MedicalCheckoutRepository Repo = new MedicalCheckoutRepository())
                {
                    var _availedMedical = Repo.GetAvailedMedicalCheckoutsListByEmployeeIdYearwise(CurrentUser.EmployeeInfoId, DateTime.Now.ToString("yyyy"));

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

                    if (medicalCheckoutInfo.Amount > remainingMedicalAmount)
                    {
                        TempData["Msg"] = AlertMessageProvider.FailureMessage("Selected amount cannot be greater than remaining medical amount.");

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

                    medicalCheckoutInfo.EmployeeInfoId = CurrentUser.EmployeeInfoId;
                    medicalCheckoutInfo.Status         = "Incomplete";

                    _medicalCheckoutId = Repo.SaveMedicalCheckout(medicalCheckoutInfo);
                }

                return(RedirectToAction("Apply", "Medical", new { id = _medicalCheckoutId }));
            }

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