public ActionResult CreateComment(int id, string body)
        {
            var ticket = db.Tickets.Where(p => p.Id == id).FirstOrDefault();
            var userId = User.Identity.GetUserId();

            if (ticket == null)
            {
                return(HttpNotFound());
            }

            if (string.IsNullOrWhiteSpace(body))
            {
                TempData["Errormessage"] = "Comment is Mandatory";
                return(RedirectToAction("Details", new { id }));
            }
            var comment = new TicketComment();

            comment.UserId   = User.Identity.GetUserId();
            comment.TicketId = ticket.Id;
            comment.Created  = DateTime.Now;
            comment.Comment  = body;
            db.TicketComments.Add(comment);
            var user = db.Users.FirstOrDefault(p => p.Id == comment.UserId);
            var personalEmailService = new PersonalEmailServices();
            var mailMessage          = new MailMessage(WebConfigurationManager.AppSettings["emailto"], user.Email);

            mailMessage.Body       = "Someone commented on your Ticket";
            mailMessage.Subject    = "Comment";
            mailMessage.IsBodyHtml = true;
            personalEmailService.Send(mailMessage);

            db.SaveChanges();
            return(RedirectToAction("Details", new { id }));
        }
        public ActionResult AssignDeveloper(AssignDevelopersTicketModel model)
        {
            var ticket = db.Tickets.FirstOrDefault(p => p.Id == model.TicketId);

            ticket.AssigneeId = model.SelectedDeveloperId;
            var user = db.Users.FirstOrDefault(p => p.Id == model.SelectedDeveloperId);
            var personalEmailService = new PersonalEmailServices();
            var mailMessage          = new MailMessage(WebConfigurationManager.AppSettings["emailto"], user.Email);

            mailMessage.Body       = "Someone Assign you a ticket";
            mailMessage.Subject    = "Assign";
            mailMessage.IsBodyHtml = true;
            personalEmailService.Send(mailMessage);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 //[Authorize(Roles = "Submitter")]
 public ActionResult CreateAttachment(int ticketId, [Bind(Include = "Id,Description,TicketTypeId")] TicketAttachment ticketAttachment, HttpPostedFileBase image)
 {
     if (ModelState.IsValid)
     {
         var tickets = db.Tickets.FirstOrDefault(t => t.Id == ticketId);
         if (!ImageUploadValidator.IsWebFriendlyImage(image))
         {
             TempData["ErrorMessage"] = "uploading image is Mandatory";
             return(RedirectToAction("Details", new { id = ticketId }));
         }
         if (image == null)
         {
             return(HttpNotFound());
         }
         var FileUsed = Path.GetFileName(image.FileName);
         if (!Directory.Exists(Server.MapPath("~/Uploads/")))
         {
             Directory.CreateDirectory(Server.MapPath("~/Uploads/"));
         }
         image.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), FileUsed));
         ticketAttachment.FilePath = "/Uploads/" + FileUsed;
         ticketAttachment.UserId   = User.Identity.GetUserId();
         ticketAttachment.Created  = DateTime.Now;
         ticketAttachment.UserId   = User.Identity.GetUserId();
         ticketAttachment.TicketId = ticketId;
         db.TicketAttachments.Add(ticketAttachment);
         var user = db.Users.FirstOrDefault(p => p.Id == ticketAttachment.UserId);
         var personalEmailService = new PersonalEmailServices();
         var mailMessage          = new MailMessage(
             WebConfigurationManager.AppSettings["emailto"], user.Email);
         mailMessage.Body       = "You have a new attachment";
         mailMessage.Subject    = "New Attachment";
         mailMessage.IsBodyHtml = true;
         personalEmailService.Send(mailMessage);
         db.SaveChanges();
         return(RedirectToAction("Details", new { id = ticketId }));
     }
     return(View(ticketAttachment));
 }