public ActionResult Cancel(long id) { HRMS_Travel_Expense_App obj = db.HRMS_Travel_Expense_App.Find(id); obj.Status = 2; db.Entry(obj).State = EntityState.Modified; db.SaveChanges(); //storing total amount in Db decimal TotalAmount; long AppID = db.HRMS_Travel_Expense_App.Where(x => x.ID == id).Select(x => x.Travel_App_ID).FirstOrDefault(); int TotalCount = db.HRMS_Travel_Expense_App.Where(x => x.Travel_App_ID == AppID).Count(); int CancelCount = db.HRMS_Travel_Expense_App.Where(x => x.Travel_App_ID == AppID && x.Status == 2).Count(); if (TotalCount == CancelCount) { TotalAmount = 0; } else { TotalAmount = db.HRMS_Travel_Expense_App.Where(x => x.Travel_App_ID == AppID && (x.Status == 0 || x.Status == 1)).Sum(x => x.Amount); } HRMS_Travel_Application obj1 = db.HRMS_Travel_Application.Find(AppID); obj1.ExpenseAmount = TotalAmount; db.Entry(obj1).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("ViewExpense", new { id = obj.Travel_App_ID })); }
public bool Delete(long id) { HRMS_Travel_Expense_App obj = db.HRMS_Travel_Expense_App.Find(id); if (obj != null) { db.HRMS_Travel_Expense_App.Remove(obj); db.SaveChanges(); return(true); } else { return(false); } }
public ActionResult AddExpense(long?id) { HRMS_Travel_Expense_App obj = new HRMS_Travel_Expense_App(); obj.Travel_App_ID = id.Value; //for list ViewData["users"] = db.HRMS_Travel_Expense_App.Where(x => x.Travel_App_ID == id.Value).ToList(); //savechanges without any rows ViewBag.Error = TempData["Error"]; //ViewBag.Config = TempData["Config"]; return(View(obj)); }
public ActionResult AddExpense(HRMS_Travel_Expense_App obj, HttpPostedFileBase files) { long emp_id = Convert.ToInt64(Session["id"]); string role = db.Accounts.Where(x => x.ID == emp_id).Select(x => x.role).FirstOrDefault(); obj.EMP_ID = emp_id; //checking for configuration HRMS_EMP_GRA_POL obj1 = db.HRMS_EMP_GRA_POL.Where(x => x.Emp_ID == obj.EMP_ID).FirstOrDefault(); decimal val = db.HRMS_TRAVEL_MILEAGE_CONFIG.Where(x => x.Travel_Mileage_Emp_Grade.StartsWith(obj1.Gra_ID.ToString()) && x.Travel_Group == obj1.Pol_ID).Select(x => x.Travel_Mileage_Four).FirstOrDefault(); if (obj.Amount > (obj.Distance * val)) { obj.Warning = 1; } obj.Status = 0; //file if (files != null) { var Extension = Path.GetExtension(files.FileName); var fileName = obj.Travel_App_ID + "_" + obj.From_Place + obj.To_Place + Extension; string path = Path.Combine(Server.MapPath("~/ExpenseAttach"), fileName); obj.FileUrl = Url.Content(Path.Combine("~/ExpenseAttach/", fileName)); obj.FileName = fileName; files.SaveAs(path); } db.HRMS_Travel_Expense_App.Add(obj); db.SaveChanges(); return(RedirectToAction("AddExpense", new { id = obj.Travel_App_ID })); }
public ActionResult Edit(HRMS_Travel_Expense_App obj) { db.Entry(obj).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("AddExpense", new { id = obj.Travel_App_ID })); }
public ActionResult Edit(long?id) { HRMS_Travel_Expense_App obj = db.HRMS_Travel_Expense_App.Find(id); return(View(obj)); }