public ActionResult Script(int id) { SlotRange range = SlotRangeModel.GetSlotRange(id); string script = range.GenerateScript(); return(File(Encoding.UTF8.GetBytes(script), "text/plain", string.Format("scripts_cours_{0}.sh", id))); }
public ActionResult Delete(int id, SlotRange range) { SlotRange sr = SlotRangeModel.GetSlotRange(id); if (IsAuthorized(SlotRangeModel.GetSlotRange(id))) { try { SlotRangeModel.DeleteSlotRange(id, range); return(RedirectToAction("CourseRanges", new { id = sr.IdCourse })); } catch (GrException gex) { ModelState.AddModelError("", gex.UserMessage); // get updated data SlotRange range_ = SlotRangeModel.GetSlotRange(id); // update timestamp in case user really wants to delete this ModelState.SetModelValue("Timestamp", new ValueProviderResult(range_.Timestamp, "", CultureInfo.InvariantCulture)); // show new values before user decided to really delete them return(View(range_)); //ViewBag.ErrorMode = "la suppression"; //return View("Error", exx); } } else { SessionManager.RedirectAccessDenied(HttpContext.Request.RequestContext); return(null); } }
public ActionResult Delete(int id) { SlotRange range = SlotRangeModel.GetSlotRange(id); if (range == null) { return(View("NoSuchRange")); } int?rId = range.GetResponsible(); if (IsAuthorized(range)) { return(View(range)); } else { SessionManager.RedirectAccessDenied(HttpContext.Request.RequestContext); return(null); } }
// this method uses host-based authentication /// <summary> /// GET: /SlotRange/EmailScript/3 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult EmailScript(int id) { if (Request.Url.Host != "localhost" && Request.UserHostAddress != "127.0.0.1") { throw new Exception("access denied"); } SlotRange range = SlotRangeModel.GetSlotRange(id); if (range == null) { throw new Exception("invalid id"); } string script = range.GenerateScript(); // get email address of resource manager List <Person> persons = PersonModel.GetResourceManagers(); string resMgrs = PersonModel.GetEmailCSV(persons); // send script to resourceManager(s) via E-Mail System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(); //message.From = new System.Net.Mail.MailAddress("*****@*****.**"); message.To.Add(resMgrs); message.IsBodyHtml = false; message.Subject = "Script Linux pour le SlotRange '" + range.id_slotRange + "'"; message.BodyEncoding = System.Text.Encoding.GetEncoding("utf-8"); message.From = new System.Net.Mail.MailAddress("*****@*****.**"); message.Body = script; System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(); client.Send(message); // for demo backup, also write to a file return(View(range)); // can be implemented for testing purposes }
public ActionResult Duplicate(int id, SlotRange target) { SlotRange source = SlotRangeModel.GetSlotRange(id); if (source == null) { return(View("NoSuchRange")); } int?rId = source.GetResponsible(); if (IsAuthorized(source)) { TimeSpan span = target.StartRes - source.StartRes; int days = (int)span.TotalDays; SlotRangeModel.DuplicateSlotRange(source, days, source.IdCourse); return(RedirectToAction("CourseRanges", new { id = source.IdCourse })); } else { SessionManager.RedirectAccessDenied(HttpContext.Request.RequestContext); return(null); } }