public ActionResult DeleteConfirmed(int id) { DownTimeType downTimeTypes = db.DownTimeTypes.Find(id); db.DownTimeTypes.Remove(downTimeTypes); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,Description")] DownTimeType downTimeTypes) { if (ModelState.IsValid) { db.Entry(downTimeTypes).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(downTimeTypes)); }
public ActionResult Create([Bind(Include = "Id,Description")] DownTimeType downTimeTypes) { if (ModelState.IsValid) { db.DownTimeTypes.Add(downTimeTypes); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(downTimeTypes)); }
// GET: DownTimeTypes/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DownTimeType downTimeTypes = db.DownTimeTypes.Find(id); if (downTimeTypes == null) { return(HttpNotFound()); } return(View(downTimeTypes)); }
public ActionResult Edit([Bind(Include = "Id,DownTimeTypeId,DepartmentId,Date,Duration")] DownTimeEvent downTimeEvent) { Department thisDepartment = (Department)db.Departments.First(o => o.Id == downTimeEvent.DepartmentId); DownTimeType errorType = (DownTimeType)db.DownTimeTypes.First(o => o.Id == downTimeEvent.DownTimeTypeId); downTimeEvent.departmentName = thisDepartment.DepartmentName; downTimeEvent.ErrorTypeName = errorType.Description; downTimeEvent.EmployeeId = User.Identity.Name; if (ModelState.IsValid) { db.Entry(downTimeEvent).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(downTimeEvent)); }
public int Add(DownTimeTypeDto dto) { DownTimeType entity = Mapper.Map <DownTimeTypeDto, DownTimeType>(dto); try { _repository.Repository <DownTimeType>().Insert(entity); _repository.Save(); } catch (DbEntityValidationException valEx) { HandleValidationException(valEx); } catch (Exception ex) { LogException(ex); throw; } return(entity.ID); }
public ActionResult Create([Bind(Include = "Id,DownTimeTypeId,DepartmentId,Date,Duration")] DownTimeEvent downTimeEvent) { if (ModelState.IsValid) { Department thisDepartment = (Department)db.Departments.First(o => o.Id == downTimeEvent.DepartmentId); DownTimeType errorType = (DownTimeType)db.DownTimeTypes.First(o => o.Id == downTimeEvent.DownTimeTypeId); downTimeEvent.departmentName = thisDepartment.DepartmentName; downTimeEvent.ErrorTypeName = errorType.Description; downTimeEvent.EmployeeId = User.Identity.Name; db.DownTimeEvents.Add(downTimeEvent); db.SaveChanges(); List <DownTimeEvent> events = db.DownTimeEvents.Where(o => o.DepartmentId == downTimeEvent.DepartmentId & o.Date.Month == DateTime.Now.Month).ToList(); List <AlertThreshold> triggers = db.AlertThresholds.ToList(); int totalDowntime = 0; foreach (DownTimeEvent x in events) { totalDowntime += x.Duration; } foreach (AlertThreshold trigger in triggers) { int daysElapsed = (DateTime.Now.Day); if (totalDowntime / (435 * daysElapsed) >= trigger.PercentDowntimeThreshold / 100) { List <EmailAddress> emails = db.EmailList.ToList(); var fromAddress = new MailAddress("*****@*****.**", "Report Host"); const string fromPassword = "******"; string subject = "Down Time Alert"; string body = ("This is an automated alert that is set to notify you when a department has exceeded " + trigger.PercentDowntimeThreshold.ToString() + " percent cumulative downtime for the current reporting period. Department: " + downTimeEvent.departmentName + " To Date Downtime: " + totalDowntime + " minutes."); var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(fromAddress.Address, fromPassword) }; foreach (EmailAddress email in emails) { var toAddress = new MailAddress(email.Email); using (var message = new MailMessage(fromAddress, toAddress) { Subject = subject, Body = body }) { smtp.Send(message); } } } } if (User.IsInRole("admin")) { return(RedirectToAction("Index")); } else { return(RedirectToAction("Index", "home", null)); } } return(View(downTimeEvent)); }