public ActionResult shMapping(string hdnUsr,string hdnRid, string btnAction) { TempData["project"] = TempData["project"]; TempData["fundsMapping"] = TempData["fundsMapping"]; TempData["hdnUsr"] = hdnUsr; TempData["hdnRid"] = hdnRid; TempData["hdnFunds"] = TempData["hdnFunds"]; if (btnAction == "Back") { return RedirectToAction("create", "Projects"); } if (btnAction == "Next") { return RedirectToAction("fundsMapping", "Funds"); } //ToDo chk for page Project project = (Project)TempData["project"]; db.Projects.Add(project); db.SaveChanges(); //ToAdd: start int id = project.Id; var Db = new ApplicationDbContext(); foreach (string s in hdnUsr.Split('#')) { if (s != null && s != "") { var cnt = 0; if (db.EmployeeProjects.Count() > 0) cnt = db.EmployeeProjects.Max(x => x.Id); EmployeeProject ep = new EmployeeProject(); ep.Id = cnt + 1; ep.EmployeeId = s; ep.ProjectId = Convert.ToInt32(id); db.EmployeeProjects.Add(ep); db.SaveChanges(); } } return RedirectToAction("Index", "projects"); }
public ActionResult fundsMapping(List<Fund> lst, string hdnFunds, string btnAction) { if (btnAction == "Cancel") { TempData["project"] = null; TempData["hdnUsr"] = null; TempData["fundsMapping"] = null; TempData["hdnUsr"] = null; TempData["hdnRid"] = null; TempData["hdnFunds"] = null; TempData["isEdit"] = null; return RedirectToAction("Index", "Projects"); } TempData["project"] = TempData["project"]; TempData["hdnRid"] = TempData["hdnRid"]; TempData["hdnUsr"] = TempData["hdnUsr"]; TempData["hdnFunds"] = hdnFunds; var hdnUsr = Convert.ToString(TempData["hdnUsr"]); TempData["isEdit"] = TempData["isEdit"]; if (btnAction == "Back") { TempData["fundsMapping"] = lst; return RedirectToAction("shMapping", "Account"); } //ToDo chk for page Project project = (Project)TempData["project"]; if (Convert.ToString(TempData["isEdit"]) == "1") { Project p = db.Projects.Find(project.Id); p.Name = project.Name; p.Description = project.Description; p.StartDate = project.StartDate; p.EndDate = project.EndDate; p.City = project.City; p.Location = project.Location; p.Category = project.Category; p.ModifiedOn = DateTime.Now; db.Entry(p).State = EntityState.Modified; db.SaveChanges(); } else { db.Projects.Add(project); db.SaveChanges(); } //ToAdd: start int id = project.Id; var Db = new ApplicationDbContext(); if (Convert.ToString(TempData["isEdit"]) == "1") { var ep = from s in db.EmployeeProjects where s.ProjectId == id select s; foreach (EmployeeProject e in ep) { db.EmployeeProjects.Remove(e); } } foreach (string s in hdnUsr.Split('#')) { if (s != null && s != "") { var cnt = 0; if (db.EmployeeProjects.Count() > 0) cnt = db.EmployeeProjects.Max(x => x.Id); EmployeeProject ep = new EmployeeProject(); ep.Id = cnt + 1; ep.EmployeeId = s; ep.ProjectId = Convert.ToInt32(id); db.EmployeeProjects.Add(ep); db.SaveChanges(); } } //foreach (Fund f in lst) var sAmt = 0; var rsAmt = 0.0; if (Convert.ToString(TempData["isEdit"]) == "1") { var fp = from s in db.FundProjects where s.ProjectId == id select s; var fundItr = fp.ToList(); foreach (FundProject e in fundItr) { rsAmt += Convert.ToDouble(e.SpentAmount.Trim()); Fund p = db.Funds.Find(e.FundId); if (p.SpentAmount == null) p.SpentAmount = "0.0"; p.SpentAmount = Convert.ToString(Convert.ToInt32(Convert.ToDouble(p.SpentAmount.Trim()) - Convert.ToDouble(e.SpentAmount.Trim())) ) ; p.SpentAmount = Convert.ToString(Convert.ToInt32(Convert.ToDouble(p.SpentAmount.Trim()))); p.TotalAmount = Convert.ToString(Convert.ToInt32(Convert.ToDouble(p.TotalAmount.Trim()))); if (p.SpentAmount == "0" || Convert.ToInt32(p.SpentAmount)<0) p.SpentAmount = null; foreach (FundProject f in p.FundProjects) { if (f.SpentAmount == null) f.SpentAmount = "0.0"; f.SpentAmount = Convert.ToString(Convert.ToInt32(Convert.ToDouble(Convert.ToString(f.SpentAmount).Trim()))); if (f.SpentAmount == "0" || Convert.ToInt32(f.SpentAmount) < 0) f.SpentAmount = null; } db.Entry(p).State = EntityState.Modified; db.SaveChanges(); db.FundProjects.Remove(e); } } foreach (string s in hdnFunds.Split('#')) { if (s != null && s != "") { var idf = Convert.ToInt32(s.Split(',')[0]); Fund p = db.Funds.Find(idf); p.TotalAmount = p.TotalAmount.Trim(); if (p.SpentAmount == null) p.SpentAmount = "0.0"; p.SpentAmount = Convert.ToString(Convert.ToInt32(Convert.ToDouble(Convert.ToString(p.SpentAmount).Trim()) + Convert.ToDouble(s.Split(',')[1]))); sAmt += Convert.ToInt32(Convert.ToDouble(s.Split(',')[1])); //sAmt += Convert.ToInt32(Convert.ToInt32(s.Split(',')[1])); p.SpentAmount = p.SpentAmount.Trim(); db.Entry(p).State = EntityState.Modified; db.SaveChanges(); var cnt = 0; if (db.FundProjects.Count() > 0) cnt = db.FundProjects.Max(x => x.Id); FundProject fp = new FundProject(); fp.Id = cnt + 1; fp.FundId = Convert.ToInt32(s.Split(',')[0]); //fp.SpentAmount = Convert.ToString(s.Split(',')[1]); fp.SpentAmount = Convert.ToString(Convert.ToInt32(Convert.ToDouble(s.Split(',')[1]))); fp.SpentAmount = fp.SpentAmount.Trim(); fp.ProjectId = Convert.ToInt32(id); db.FundProjects.Add(fp); db.SaveChanges(); } } Project pe = db.Projects.Find(id); pe.TotalAllocatedAmount = Convert.ToInt32(pe.TotalAllocatedAmount) - rsAmt + sAmt; db.Entry(pe).State = EntityState.Modified; db.SaveChanges(); TempData["project"] = null; TempData["hdnUsr"] = null; TempData["fundsMapping"] = null; TempData["hdnUsr"] = null; TempData["hdnRid"] = null; TempData["isEdit"] = null; TempData["hdnFunds"] = null; return RedirectToAction("Index", "Projects"); }
public ActionResult fundsMapping(List<Fund> lst, string hdnFunds, string btnAction) { TempData["project"] = TempData["project"]; TempData["hdnRid"] = TempData["hdnRid"]; //TempData["fundsMapping"] = TempData["fundsMapping"]; TempData["hdnUsr"] = TempData["hdnUsr"]; TempData["hdnFunds"] = hdnFunds; var hdnUsr = Convert.ToString(TempData["hdnUsr"]); if (btnAction == "Back") { TempData["fundsMapping"] = lst; return RedirectToAction("shMapping", "Account"); } //ToDo chk for page Project project = (Project)TempData["project"]; db.Projects.Add(project); db.SaveChanges(); //ToAdd: start int id = project.Id; var Db = new ApplicationDbContext(); foreach (string s in hdnUsr.Split('#')) { if (s != null && s != "") { var cnt = 0; if (db.EmployeeProjects.Count() > 0) cnt = db.EmployeeProjects.Max(x => x.Id); EmployeeProject ep = new EmployeeProject(); ep.Id = cnt + 1; ep.EmployeeId = s; ep.ProjectId = Convert.ToInt32(id); db.EmployeeProjects.Add(ep); db.SaveChanges(); } } //foreach (Fund f in lst) var sAmt=0; foreach (string s in hdnFunds.Split('#')) { if (s != null && s != "") { Fund p = db.Funds.Find(s.Split(',')[0]); p.SpentAmount=Convert.ToInt16(p.SpentAmount)+s.Split(',')[1]; sAmt += Convert.ToInt16(p.SpentAmount); db.Entry(p).State = EntityState.Modified; db.SaveChanges(); var cnt = 0; if (db.FundProjects.Count() > 0) cnt = db.FundProjects.Max(x => x.Id); FundProject fp = new FundProject(); fp.Id = cnt + 1; fp.FundId = Convert.ToInt32(s.Split(',')[0]); fp.SpentAmount = Convert.ToString(s.Split(',')[1]); fp.ProjectId = Convert.ToInt32(id); db.FundProjects.Add(fp); db.SaveChanges(); } Project pe = db.Projects.Find(id); pe.TotalAllocatedAmount=Convert.ToInt16(pe.TotalAllocatedAmount)+sAmt; db.Entry(pe).State = EntityState.Modified; db.SaveChanges(); } return RedirectToAction("Index", "Home"); }