public ActionResult Create([Bind(Include = "Id,MaintenacesObjectId,DateTimeStart,DateTimeEnd,IsConfirm,ReportText")] PerformMaintenanceReport performMaintenanceReport) { if (User.Identity.Name == "") { throw new Exception("Access not denid"); } string access_type = db.StaffPersons.Where(p => p.UserName == User.Identity.Name).First().AccessType; if (access_type != "Administrator" && access_type != "Chef" && access_type != "Specialist") { throw new Exception("Access not denid"); } performMaintenanceReport.CreateUserName = performMaintenanceReport.ModifyUserName = User.Identity.Name; performMaintenanceReport.CreateDate = performMaintenanceReport.ModifyDate = new MDTime().GetCurrentTime(); performMaintenanceReport.IsConfirm = false; if (ModelState.IsValid) { db.PerformMaintenanceReports.Add(performMaintenanceReport); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MaintenacesObjectId = new SelectList(db.MaintenacesObjects, "Id", "Description", performMaintenanceReport.MaintenacesObjectId); return(View(performMaintenanceReport)); }
public ActionResult DeleteConfirmed(int id) { PerformMaintenanceReport performMaintenanceReport = db.PerformMaintenanceReports.Find(id); if (User.Identity.Name == "") { throw new Exception("Access not denid"); } string access_type = db.StaffPersons.Where(p => p.UserName == User.Identity.Name).First().AccessType; if (access_type != "Administrator" && access_type != "Chef" && access_type != "Specialist") { throw new Exception("Access not denid"); } if (access_type == "Specialist" && User.Identity.Name != performMaintenanceReport.CreateUserName) { throw new Exception("Access not denid"); } if (performMaintenanceReport.IsConfirm != false) { throw new Exception("Access not denid"); } db.PerformMaintenanceReports.Remove(performMaintenanceReport); db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: PerformMaintenanceReports/Delete/5 public ActionResult Delete(int?id) { if (User.Identity.Name == "") { throw new Exception("Access not denid"); } string access_type = db.StaffPersons.Where(p => p.UserName == User.Identity.Name).First().AccessType; if (access_type != "Administrator" && access_type != "Chef" && access_type != "Specialist") { throw new Exception("Access not denid"); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PerformMaintenanceReport performMaintenanceReport = db.PerformMaintenanceReports.Find(id); if (access_type == "Specialist" && User.Identity.Name != performMaintenanceReport.CreateUserName) { throw new Exception("Access not denid"); } if (performMaintenanceReport.IsConfirm != false) { throw new Exception("Access not denid"); } if (performMaintenanceReport == null) { return(HttpNotFound()); } return(View(performMaintenanceReport)); }
public ActionResult Confirm(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PerformMaintenanceReport performMaintenanceReport = db.PerformMaintenanceReports.Find(id); if (performMaintenanceReport == null) { return(HttpNotFound()); } if (User.Identity.Name == "") { throw new Exception("Access not denid"); } string access_type = db.StaffPersons.Where(p => p.UserName == User.Identity.Name).First().AccessType; if (access_type != "Administrator" && access_type != "Chef") { throw new Exception("Access not denid"); } performMaintenanceReport.IsConfirm = true; db.Entry(performMaintenanceReport).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Report(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } MaintenacesObject maintenacesObject = db.MaintenacesObjects.Find(id); if (maintenacesObject == null) { return(HttpNotFound()); } string access_type = db.StaffPersons.Where(p => p.UserName == User.Identity.Name).First().AccessType; if (User.Identity.Name == "") { throw new Exception("Access not denid"); } if (access_type != "Administrator" && access_type != "Chef" && access_type != "Specialist") { throw new Exception("Access not denid"); } PerformMaintenanceReport obj = new PerformMaintenanceReport(); obj.DateTimeEnd = obj.DateTimeStart = new MDTime().GetCurrentTime(); obj.MaintenacesObjectId = maintenacesObject.Id; obj.MaintenacesObject = maintenacesObject; ViewBag.MaintenanceDescription = maintenacesObject.Description; return(View(obj)); }
// GET: PerformMaintenanceReports/Create public ActionResult Create() { if (User.Identity.Name == "") { throw new Exception("Access not denid"); } string access_type = db.StaffPersons.Where(p => p.UserName == User.Identity.Name).First().AccessType; if (access_type != "Administrator" && access_type != "Chef" && access_type != "Specialist") { throw new Exception("Access not denid"); } ViewBag.MaintenacesObjectId = new SelectList(db.MaintenacesObjects, "Id", "Description"); PerformMaintenanceReport obj = new PerformMaintenanceReport(); obj.DateTimeEnd = obj.DateTimeStart = new MDTime().GetCurrentTime(); return(View(obj)); }