public ActionResult Details(string id)
        {
            try
            {
                if (Request.IsAuthenticated)
                {
                    AuthenticateUser();

                    if (id == null)
                    {
                        return(RedirectToAction(UrlIndex, UrlOpdExpense));
                    }

                    int idDecrypted = Security.DecryptId(Convert.ToString(id));
                    var result2     = GeneralController.GetTravelExpense(idDecrypted, _opdExpenseService, _travelExpenseService);
                    return(View(result2));
                }
                else
                {
                    return(RedirectToAction("Details()", UrlOpdExpense));
                }
            }
            catch (Exception ex)
            {
                logger.Error("OPD Expense : Details" + ex.Message.ToString());

                return(View(new HttpStatusCodeResult(HttpStatusCode.BadRequest)));
            }
        }
        private bool AuthenticateEmailAddress(int Id)
        {
            var opdInformation = GeneralController.GetTravelExpense(Convert.ToInt32(Id), _opdExpenseService, _travelExpenseService);
            OfficeManagerController managerController = new OfficeManagerController();

            string currentEmailAddress = managerController.GetEmailAddress();

            if (currentEmailAddress.Equals(opdInformation.EmployeeEmailAddress))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        private bool GetTravelExpenseAmount(int Id, decimal?totalAmountClaimed)
        {
            bool result = false;

            var opdInformation = GeneralController.GetTravelExpense(Id, _opdExpenseService, _travelExpenseService);

            decimal?totalAmount = 0;

            for (int count = 0; count <= opdInformation.ListTravelExpense.Count - 1; count++)
            {
                totalAmount += opdInformation.ListTravelExpense[count].Amount;
            }

            if (totalAmount.Equals(totalAmountClaimed))
            {
                result = true;
            }

            return(result);
        }
        public ActionResult Edit(string id)
        {
            try
            {
                if (Request.IsAuthenticated)
                {
                    AuthenticateUser();
                    if (id == null)
                    {
                        return(RedirectToAction(UrlIndex, UrlOpdExpense));
                    }

                    int idDecrypted = Security.DecryptId(Convert.ToString(id));

                    var opdInformation = GeneralController.GetTravelExpense(Convert.ToInt32(idDecrypted), _opdExpenseService, _travelExpenseService);
                    ViewData["OPDEXPENSE_ID"]  = idDecrypted;
                    ViewData["OPDTYPE"]        = opdInformation.OpdType;
                    ViewBag.EmployeeDepartment = opdInformation.EmployeeDepartment;

                    if (!(AuthenticateEmailAddress(Convert.ToInt32(idDecrypted))))
                    {
                        return(RedirectToAction(UrlIndex, UrlHome));
                    }


                    return(View(opdInformation));
                }
                else
                {
                    return(RedirectToAction(UrlIndex, UrlOpdExpense));
                }
            }
            catch (Exception ex)
            {
                logger.Error("Travel Expense : Edit()" + ex.Message.ToString());

                return(View(new HttpStatusCodeResult(HttpStatusCode.BadRequest)));
            }
        }
        public ActionResult Edit(OpdExpenseVM OpdExpense)
        {
            try
            {
                string buttonStatus = Request.Form["buttonName"];

                AuthenticateUser();
                var opdInformation = GeneralController.GetTravelExpense(OpdExpense.ID, _opdExpenseService, _travelExpenseService);
                ViewData["OPDEXPENSE_ID"]  = OpdExpense.ID;
                ViewData["OPDTYPE"]        = OpdExpense.OpdType;
                ViewBag.EmployeeDepartment = opdInformation.EmployeeDepartment;

                if (buttonStatus == "submit")
                {
                    OpdExpense.Status = ClaimStatus.FININPROCESS;
                }
                else
                {
                    OpdExpense.Status = ClaimStatus.INPROGRESS;
                }


                if (OpdExpense.Status == ClaimStatus.FININPROCESS)
                {
                    if (opdInformation.ListTravelExpense.Count > 0)
                    {
                        if (GetTravelExpenseAmount(OpdExpense.ID, OpdExpense.TotalAmountClaimed))
                        {
                            if (ModelState.IsValid)
                            {
                                OpdExpense.ModifiedDate         = DateTime.Now;
                                OpdExpense.EmployeeEmailAddress = GetEmailAddress();
                                _opdExpenseService.UpdateOpdExpense(OpdExpense);
                                return(RedirectToAction(UrlIndex, UrlOpdExpense));
                            }
                        }
                        else
                        {
                            ModelState.AddModelError("", Constants.MSG_GENERAL_TRAVEL_EXPENSE_AMOUNT);
                            return(View(opdInformation));
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", Constants.MSG_GENERAL_ADD_TRAVEL_EXPENSE_RECEIPTS);
                        return(View(opdInformation));
                    }
                }
                else
                {
                    if (ModelState.IsValid)
                    {
                        OpdExpense.CreatedDate          = DateTime.Now;
                        OpdExpense.ModifiedDate         = DateTime.Now;
                        OpdExpense.EmployeeEmailAddress = GetEmailAddress();
                        _opdExpenseService.UpdateOpdExpense(OpdExpense);
                        return(RedirectToAction(UrlIndex, UrlOpdExpense));
                    }
                }

                return(View(opdInformation));
            }
            catch (Exception ex)
            {
                logger.Error("Travel Expense : Edit([Bind])" + ex.Message.ToString());

                return(View(new HttpStatusCodeResult(HttpStatusCode.BadRequest)));
            }
        }