public IHttpActionResult PutDiskChecker(int id, DiskChecker diskChecker) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != diskChecker.ID) { return(BadRequest()); } db.Entry(diskChecker).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!DiskCheckerExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Edit([Bind(Include = "ID,ServerName,DriveLetter,LowDiskPercentage,PollTime,AdminEmailAlert,AlertSubscribers,SubcriptionEmailAddresses,Disable,ShowOnDash,LastRan,DriveSize,AvailableSpace,IgnorePollTimeOnNextRun")] DiskChecker diskChecker) { if (ModelState.IsValid) { db.Entry(diskChecker).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(diskChecker)); }
public static bool DiskSpaceCheck() { DiskSuccess = false; try { using (var context = new DriveSpaceDBContext()) { var DiskRecords = context.DiskCheckers.ToList(); foreach (var i in DiskRecords) { if (!i.Disable) { DiskSpace availableSpace = GetDriveSpace(i.ServerName, i.DriveLetter); //Update DB var Update = context.DiskCheckers.Find(i.ID); Update.AvailableSpace = availableSpace.RemainingSpace.ToString(); Update.DriveSize = availableSpace.TotalSpace.ToString(); Update.LastRan = Convert.ToDateTime(DateTimeNow); //Update.LowDiskPercentage = Convert.ToInt32(availableSpace.PercentageOfSpaceRemaining); // Mark as Changed context.Entry(Update).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); if (i.AdminEmailAlert == true || i.AlertSubscribers == true) { //If emails are needed, check to see if any alerts need to be sent if (Convert.ToDateTime(i.LastRan).AddMinutes(i.PollTime) <= Convert.ToDateTime(DateTimeNow)) { int LowPercentageAlert = Convert.ToInt32(i.LowDiskPercentage); int CurrentPercentage = Convert.ToInt32(availableSpace.PercentageOfSpaceRemaining); //Is the disk in a low disk state if (LowPercentageAlert > CurrentPercentage) { //Send Email string AllEmailAddresses = string.Empty; //Get Addresses if (i.AdminEmailAlert) { AllEmailAddresses = "*****@*****.**"; } if (i.AlertSubscribers = true && AllEmailAddresses == string.Empty) { AllEmailAddresses = AllEmailAddresses + ", " + i.SubcriptionEmailAddresses; } else if (i.AlertSubscribers) { AllEmailAddresses = i.SubcriptionEmailAddresses; } else { //log } string EmailSubject = EmailTemplate.EmailSubject(i.ServerName, i.DriveLetter); string HtmlBody = EmailTemplate.EmailBody(i.ServerName, i.DriveLetter, availableSpace.PercentageOfSpaceRemaining, availableSpace.RemainingSpace, availableSpace.TotalSpace); bool EmailSuccess = EmailAlets.SendEmail(HtmlBody, EmailSubject, AllEmailAddresses); //Log Email Success } else { // } } } } } } DiskSuccess = true; } catch { } return(DiskSuccess); }