public ActionResult Create(CreateModel model, string returnUrl)
 {
     using (var db = new IntercomContext())
     {
         if (!WebSecurity.IsAuthenticated)
         {
             ModelState.AddModelError("", "Please Log in first");
         }
         db.Tickets.Add(new Ticket {
             Assignee = 1, BuildingID = model.BuildingID, CallerName = model.CallerName, Description = model.Description, Email = model.Email, Phone = model.Phone, Status = TicketStatus.New, StatusReason = "New ticket"
         });
         try
         {
             db.SaveChanges();
         }
         catch (DbEntityValidationException dbEx)
         {
             foreach (var validationErrors in dbEx.EntityValidationErrors)
             {
                 foreach (var validationError in validationErrors.ValidationErrors)
                 {
                     System.Console.WriteLine("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                 }
             }
         }
         return(RedirectToAction("Index", "Home"));
     }
 }
 public ActionResult Add(int UserID, int TicketID)
 {
     string[] roles = Roles.GetRolesForUser(WebSecurity.CurrentUserName);
     if (!(roles.Contains("Operator") || roles.Contains("Engineer")))
     {
         //A potentially dangerous Request.Path value was detected from the client (:) exception appearing
         //return Request.UrlReferrer == null ? RedirectToAction("Index","Home") : RedirectToAction(Request.UrlReferrer.ToString());
         return(RedirectToAction("Index", "Home"));
     }
     using (var db = new IntercomContext())
     {
         Ticket ticket = db.Tickets.Find(TicketID);
         if (ticket == null)
         {
             return(HttpNotFound());
         }
         else
         {
             ticket.Assignee = UserID;
             ticket.Status   = TicketStatus.Assigned;
             db.SaveChanges();
             return(RedirectToAction("Index", "Home"));
         }
     }
 }
 public ActionResult Edit(EditModel model)
 {
     using (var db = new IntercomContext())
     {
         Ticket EditedTicket = db.Tickets.Find(model.ObjectID);
         EditedTicket.Assignee     = model.Assignee;
         EditedTicket.BuildingID   = model.BuildingID;
         EditedTicket.CallerName   = model.CallerName;
         EditedTicket.Description  = model.Description;
         EditedTicket.Email        = model.Email;
         EditedTicket.Phone        = model.Phone;
         EditedTicket.Status       = model.Status;
         EditedTicket.StatusReason = model.StatusReason;
         db.SaveChanges();
     }
     return(RedirectToAction("Index", "Home"));
 }