public ActionResult Edit(int id, Employee employee) { try { using (DBuserSignupLoginEntities3 db = new DBuserSignupLoginEntities3()) { db.Entry(employee).State = EntityState.Modified; db.SaveChanges(); TempData["message"] = "Employee details for employee id " + id + " has been updated successfully!"; return(RedirectToAction("Edit", "EmployeeInsert")); } //return View(); } catch { return(View()); } }
public ActionResult Edit(int id, Task_report task_Report, Team_names team) { try { if (task_Report.risk == "Help") { task_Report.risk = "1"; } else if (task_Report.risk == null) { task_Report.risk = "0"; } if (String.IsNullOrEmpty(task_Report.emp_id.ToString()) || String.IsNullOrEmpty(task_Report.start_date) || String.IsNullOrEmpty(task_Report.end_date) || String.IsNullOrEmpty(task_Report.team_name) || String.IsNullOrEmpty(task_Report.summary) || String.IsNullOrEmpty(task_Report.task_duration.ToString())) { ViewBag.Notification = "Id/start date/end date/summary/team name are required"; return(View()); } else if (String.IsNullOrEmpty(task_Report.start_date) || String.IsNullOrEmpty(task_Report.end_date)) { ViewBag.Notification = "start date and end date are required"; return(View()); } else if (db.Employees.All(x => x.id != task_Report.emp_id)) { ViewBag.Notification = "This employee id does not exists"; return(View()); } else if (Convert.ToInt32(Session["IdUsSS1"]) != task_Report.emp_id) { ViewBag.Notification = "employee id can't be changed"; return(View()); } else if (db.Team_names.All(x => x.Team_name != task_Report.team_name)) { ViewBag.Notification = "The team name does not exists"; return(View()); } else if (task_Report.risk.ToString() == "1") { if (String.IsNullOrEmpty(task_Report.risk_details) || String.IsNullOrEmpty(task_Report.risk_resolution)) { ViewBag.Notification = "Risk details and risk resolution are required"; } else { DateTime startD = DateTime.Parse(task_Report.start_date); DateTime endD = DateTime.Parse(task_Report.end_date); double calcBusinessDays = 1 + ((endD - startD).TotalDays * 5 - (startD.DayOfWeek - endD.DayOfWeek) * 2) / 7; if (endD.DayOfWeek == DayOfWeek.Saturday) { calcBusinessDays--; } if (startD.DayOfWeek == DayOfWeek.Sunday) { calcBusinessDays--; } task_Report.task_duration = (int)calcBusinessDays; task_Report.Active = 1; ViewData["msg"] = task_Report; db.Task_report.Add(task_Report); db.SaveChanges(); //ViewBag.Notification1 = "The task report has been successfully created!"; TempData["message"] = "Task Report has been updated successfully!"; return(RedirectToAction("Edit", "Task_Report")); } return(View()); } else { DateTime startD = DateTime.Parse(task_Report.start_date); DateTime endD = DateTime.Parse(task_Report.end_date); double calcBusinessDays = 1 + ((endD - startD).TotalDays * 5 - (startD.DayOfWeek - endD.DayOfWeek) * 2) / 7; if (endD.DayOfWeek == DayOfWeek.Saturday) { calcBusinessDays--; } if (startD.DayOfWeek == DayOfWeek.Sunday) { calcBusinessDays--; } task_Report.task_duration = (int)calcBusinessDays; task_Report.Active = 1; db.Entry(task_Report).State = EntityState.Modified; db.SaveChanges(); TempData["message"] = "Task Report has been updated successfully!"; return(RedirectToAction("Edit", "Task_Report")); } } catch { return(View()); } }