public static void SendNotification(Ticket ticket, string Details) { db = new ApplicationDbContext(); var user = db.Users.FirstOrDefault(p => p.Id == ticket.AssignId); var personalEmailService = new PersonalEmailService(); var mailMessage = new MailMessage(WebConfigurationManager.AppSettings["emailto"], user.Email); mailMessage.IsBodyHtml = true; switch (Details) { case "Comment": mailMessage.Body = "Your '" + ticket.TicketProject.Name + "' ticket Has a new comment added by other user"; mailMessage.Subject = "Tickets Comment"; break; case "Attechment": mailMessage.Body = "Your '" + ticket.TicketProject.Name + "' Has a new Attechments added by other user"; mailMessage.Subject = "Tickets Attechments"; break; case "Assign": mailMessage.Body = "You are assign to a new ticket '" + ticket.TicketProject.Name + "'"; mailMessage.Subject = "Tickets Assign"; break; case "Edit": mailMessage.Body = "There is a new update on your '" + ticket.TicketProject.Name + "' ticket"; mailMessage.Subject = "Tickets update"; break; } personalEmailService.Send(mailMessage); TrackerHub.SendNotificationToUser(ticket.Assign.UserName, mailMessage.Body); }
public ActionResult CreateComment(int id, string body) { var ticket = db.Ticket .Where(p => p.Id == id) .FirstOrDefault(); if (ticket == null) { return(HttpNotFound()); } if (string.IsNullOrWhiteSpace(body)) { ViewBag.ErrorMessage = "Must require a comment..!!"; return(View("Details", new { ticket.Id })); } var comment = new TicketComments(); 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 PersonalEmailService(); var mailMessage = new MailMessage( WebConfigurationManager.AppSettings["emailto"], user.Email ); mailMessage.Body = "New comment added"; mailMessage.Subject = "New Comment"; mailMessage.IsBodyHtml = true; personalEmailService.Send(mailMessage); db.SaveChanges(); return(RedirectToAction("Details", new { id })); }
public async Task <ActionResult> Contact(EmailModel model) { if (ModelState.IsValid) { try { var body = "<p>Email From: <bold>{0}</bold>({1})</p><p>Message:</p><p>{2}</p> "; var from = WebConfigurationManager.AppSettings["emailto"]; var email = new MailMessage(from, ConfigurationManager.AppSettings["emailto"]) { Subject = model.Subject, Body = string.Format(body, model.FromName, model.FromEmail, model.Body), IsBodyHtml = true }; var svc = new PersonalEmailService(); await svc.SendAsync(email); ModelState.Clear(); return(View(new EmailModel())); } catch (Exception ex) { Console.WriteLine(ex.Message); await Task.FromResult(0); } } return(View(model)); }
public ActionResult CreateAttachment(int ticketId, [Bind(Include = "Id,Description,TicketTypeId")] TicketAttachments ticketAttachments, HttpPostedFileBase image) { if (ModelState.IsValid) { if (image == null) { return(HttpNotFound()); } if (!ImageUploadValidator.IsWebFriendlyImage(image)) { ViewBag.ErrorMessage = "upload image here"; } var fileName = Path.GetFileName(image.FileName); image.SaveAs(Path.Combine(Server.MapPath("~/ImgUploads/"), fileName)); ticketAttachments.FilePath = "/ImgUploads/" + fileName; ticketAttachments.UserId = User.Identity.GetUserId(); ticketAttachments.Created = DateTime.Now; ticketAttachments.UserId = User.Identity.GetUserId(); ticketAttachments.TicketId = ticketId; db.TicketAttachments.Add(ticketAttachments); var user = db.Users.FirstOrDefault(p => p.Id == ticketAttachments.UserId); var personalEmailService = new PersonalEmailService(); var mailMessage = new MailMessage( WebConfigurationManager.AppSettings["emailto"], user.Email ); mailMessage.Body = "New Attachment"; mailMessage.Subject = "Add Attachment"; mailMessage.IsBodyHtml = true; personalEmailService.Send(mailMessage); db.SaveChanges(); return(RedirectToAction("Details", new { id = ticketId })); } return(View(ticketAttachments)); }
public ActionResult CreateAttachment(int id, string UserId, [Bind(Include = "Description,FilePath")] TicketAttachment ticketAttachment, HttpPostedFileBase image) { if (ModelState.IsValid) { if (User.Identity.IsAuthenticated) { if (ImageUploadValidator.IsWebFriendlyImage(image)) { var fileName = Path.GetFileName(image.FileName); image.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName)); ticketAttachment.FilePath = "/Uploads/" + fileName; } ticketAttachment.TicketId = id; ticketAttachment.UserId = User.Identity.GetUserId(); ticketAttachment.Created = DateTime.Now; db.Attachments.Add(ticketAttachment); db.SaveChanges(); var ticket = db.Tickets.Where(p => p.Id == ticketAttachment.TicketId).FirstOrDefault(); if (ticket.AssigneeId != null) { var personalEmailService = new PersonalEmailService(); var mailMessage = new MailMessage(WebConfigurationManager.AppSettings["emailto"], ticket.Assignee.Email); mailMessage.IsBodyHtml = true; personalEmailService.Send(mailMessage); } return(RedirectToAction("Details", new { id = id })); } } ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title", ticketAttachment.TicketId); return(View(ticketAttachment)); }
public IHttpActionResult Invite(InviteUserViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var CreatorId = User.Identity.GetUserId(); var household = db.HouseHolds.Where(p => p.Id == model.Id).FirstOrDefault(); var invitedUser = db.Users.Where(p => p.Email == model.Email).FirstOrDefault(); if (invitedUser == null && household == null) { return(NotFound()); } if (CreatorId == household.CreatorId) { var personalEmailService = new PersonalEmailService(); var mailMessage = new MailMessage(WebConfigurationManager.AppSettings["emailto"], model.Email); mailMessage.IsBodyHtml = true; personalEmailService.Send(mailMessage); var houseHoldInvites = new HouseHoldInvites(); houseHoldInvites.HouseHoldId = household.Id; //houseHoldInvites.InvitedUserId = invitedUser.Id; db.HouseHoldInvites.Add(houseHoldInvites); db.SaveChanges(); return(Ok()); } else { return(BadRequest("not found")); } }
public ActionResult ADEdit([Bind(Include = "Id,Title,Description,Updated,ProjectId,TicketTypeId,TicketPriorityId,TicketStatusId,AssignedToUserId")] Tickets tickets) { if (ModelState.IsValid) { var changes = new List <TickectsHistory>(); var MyTicket = db.Tickets.First(p => p.Id == tickets.Id); MyTicket.Id = tickets.Id; MyTicket.Title = tickets.Title; MyTicket.Description = tickets.Description; MyTicket.Updated = DateTimeOffset.Now; MyTicket.TicketTypeId = tickets.TicketTypeId; MyTicket.TicketPriorityId = tickets.TicketPriorityId; MyTicket.TicketStatusId = tickets.TicketStatusId; MyTicket.ProjectId = tickets.ProjectId; var originalValues = db.Entry(MyTicket).OriginalValues; var currentValues = db.Entry(MyTicket).CurrentValues; foreach (var property in originalValues.PropertyNames) { var originalValue = originalValues[property]?.ToString(); var currentValue = currentValues[property]?.ToString(); if (originalValue != currentValue) { var history = new TickectsHistory(); history.Changed = DateTimeOffset.Now; history.NewValue = GetValueFromKey(property, currentValue); history.OldValue = GetValueFromKey(property, originalValue); history.Property = property; history.TicketsId = MyTicket.Id; history.UsersId = User.Identity.GetUserId(); changes.Add(history); } } db.TickectsHistories.AddRange(changes); db.SaveChanges(); var devId = db.Roles.Where(p => p.Name == "Developer").Select(p => p.Id).FirstOrDefault(); if (MyTicket.AssignedToUser.Roles.Any(p => p.RoleId == devId)) { var personalEmailService = new PersonalEmailService(); var mailMessage = new MailMessage( WebConfigurationManager.AppSettings["emailto"], MyTicket.AssignedToUser.Email ); mailMessage.Body = "Your ticket has changed, please confirm it as soon as possible"; mailMessage.Subject = "Ticket status changed"; mailMessage.IsBodyHtml = true; personalEmailService.Send(mailMessage); } return(RedirectToAction("AdminIndex")); } ViewBag.ProjectId = new SelectList(db.Projects, "Id", "Name", tickets.Id); ViewBag.TicketPriorityId = new SelectList(db.TicketPriority, "Id", "Name", tickets.TicketPriorityId); ViewBag.TicketStatusId = new SelectList(db.TicketStatus, "Id", "Name", tickets.TicketStatusId); ViewBag.TicketTypeId = new SelectList(db.TicketType, "Id", "Name", tickets.TicketTypeId); return(View("Edit", tickets)); }
public ActionResult Attachment([Bind(Include = "TicketId,Description,Created,UserId,FileUrl")] int id, TicketAttachments ticketAttachments, HttpPostedFileBase image) { if (ModelState.IsValid) { if (ImageUploadValidator.IsWebFriendlyImage(image)) { var fileName = Path.GetFileName(image.FileName); image.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName)); ticketAttachments.FileUrl = "/Uploads/" + fileName; } ticketAttachments.Created = DateTime.Now; ticketAttachments.UserId = User.Identity.GetUserId(); ticketAttachments.TicketId = id; db.TicketAttachments.Add(ticketAttachments); db.SaveChanges(); var Tickets = db.Tickets.Where(x => x.Id == ticketAttachments.TicketId).FirstOrDefault(); if (Tickets.AssigneeId != null) { var personalEmailService = new PersonalEmailService(); var mailMessage = new MailMessage(WebConfigurationManager.AppSettings["emailto"], Tickets.Assignee.Email); mailMessage.Body = "added attachment"; mailMessage.IsBodyHtml = true; personalEmailService.Send(mailMessage); } return(RedirectToAction("Index", "Tickets")); } ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title", ticketAttachments.TicketId); ViewBag.UserId = new SelectList(db.Users, "Id", "Name", ticketAttachments.UserId); return(View(ticketAttachments)); }
public async Task <ActionResult> Contact(EmailModel model) { if (ModelState.IsValid) { try { var body = "<p>Email From: <bold>{0}</bold> ({1})</p><p>Message:</p><p>{2}</p>"; var from = $"Bug-A-Boo<{model.FromEmail}>"; //model.Body = "This is a message from your blog site. The name and the email of the contacting person is above."; var email = new MailMessage(from, ConfigurationManager.AppSettings["emailto"]) { Subject = model.Subject, Body = string.Format(body, model.FromName, model.FromEmail, model.Body), IsBodyHtml = true }; var svc = new PersonalEmailService(); await svc.SendAsync(email); return(RedirectToAction("Index", "Home")); } catch (Exception ex) { Console.WriteLine(ex.Message); await Task.FromResult(0); } } return(RedirectToAction("Index", "Home")); }
public ActionResult Edit([Bind(Include = "Id,Name,Description,TicketTypeId,TicketPriorityId,TicketStatusId,CreatorId,AssigneeId,BugId")] Ticket ticket) { if (ModelState.IsValid) { var dateChanged = DateTimeOffset.Now; var changes = new List <TicketHistories>(); // db.Entry(ticket).State = EntityState.Modified; var DbTicket = db.Ticket.FirstOrDefault(p => p.Id == ticket.Id); DbTicket.Name = ticket.Name; DbTicket.Description = ticket.Description; DbTicket.TicketTypeId = ticket.TicketTypeId; DbTicket.Updated = dateChanged; var originalValues = db.Entry(DbTicket).OriginalValues; var currentValues = db.Entry(DbTicket).CurrentValues; foreach (var property in originalValues.PropertyNames) { var originalValue = originalValues[property]?.ToString(); var currentValue = currentValues[property]?.ToString(); if (originalValue != currentValue) { var history = new TicketHistories(); history.Changed = dateChanged; history.NewValue = GetValueFromKey(property, currentValue); history.OldValue = GetValueFromKey(property, originalValue); history.Property = property; history.TicketId = DbTicket.Id; history.UserId = User.Identity.GetUserId(); changes.Add(history); } } db.TicketHistories.AddRange(changes); db.SaveChanges(); if (DbTicket.AssigneeId != null) { var user = db.Users.FirstOrDefault(p => p.Id == DbTicket.AssigneeId); var personalEmailService = new PersonalEmailService(); var mailMessage = new MailMessage( WebConfigurationManager.AppSettings["emailto"], user.Email ); mailMessage.Body = "Edit Ticket by Developer"; mailMessage.Subject = "Edit Tickets"; mailMessage.IsBodyHtml = true; personalEmailService.Send(mailMessage); } return(RedirectToAction("Index")); } ViewBag.AssigneeId = new SelectList(db.Users, "Id", "FirstName", ticket.AssigneeId); ViewBag.BugId = new SelectList(db.Bugs, "Id", "Name", ticket.BugId); ViewBag.CreatorId = new SelectList(db.Users, "Id", "FirstName", ticket.CreatorId); ViewBag.TicketPriorityId = new SelectList(db.TicketPriority, "Id", "Name", ticket.TicketPriorityId); ViewBag.TicketStatusId = new SelectList(db.TicketStatus, "Id", "Name", ticket.TicketStatusId); ViewBag.TicketTypeId = new SelectList(db.TicketType, "Id", "Name", ticket.TicketTypeId); return(View(ticket)); }
public Task SendAsync(IdentityMessage message) { var personalEmailService = new PersonalEmailService(); var mailMessage = new MailMessage( WebConfigurationManager.AppSettings["emailto"], message.Destination ); mailMessage.IsBodyHtml = true; return(personalEmailService.SendAsync(mailMessage)); }
public ActionResult CreateComment(int id, string body, IdentityMessage message) { var ticketcomment = db.TicketModels.Where(p => p.Id == id).FirstOrDefault(); if (ticketcomment == null) { return(HttpNotFound()); } if (string.IsNullOrWhiteSpace(body)) { TempData["ErrorMessage"] = "Comment is required"; return(RedirectToAction("Details", new { id = id })); } var comment = new TicketComment(); comment.UserId = User.Identity.GetUserId(); comment.TicketId = ticketcomment.Id; comment.Created = DateTime.Now; comment.Comment = body; db.TicketComments.Add(comment); //Step 1: Find if there is a developer assigned to the ticket //Step 2: If yes, send him an e-email var attachmentFind = db.Users.Where(t => t.Id == comment.UserId).FirstOrDefault(); var email = WebConfigurationManager.AppSettings["emailto"]; var personalEmailService = new PersonalEmailService(); var mailMessage = new MailMessage( WebConfigurationManager.AppSettings["emailto"], attachmentFind.Email ); mailMessage.Body = "fake"; mailMessage.Subject = "comments"; mailMessage.IsBodyHtml = true; personalEmailService.Send(mailMessage); db.SaveChanges(); return(RedirectToAction("Details", new { id = id })); }
public Task SendAsync(IdentityMessage message) { var personalEmailService = new PersonalEmailService(); var mailMessage = new MailMessage( WebConfigurationManager.AppSettings["username"], message.Destination ); mailMessage.Body = message.Body; mailMessage.Subject = message.Subject; return(personalEmailService.SendAsync(mailMessage)); }
public Task SendAsync(IdentityMessage message) { // Plug in your email service here to send an email. var personalEmailService = new PersonalEmailService(); var mailMessage = new MailMessage( WebConfigurationManager.AppSettings["emailto"], message.Destination ); mailMessage.Body = message.Body; mailMessage.Subject = message.Subject; mailMessage.IsBodyHtml = true; return personalEmailService.SendAsync(mailMessage); }
public async Task <ActionResult> Register(ExtendedRegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { FirstName = model.FirstName, LastName = model.LastName, UserName = model.Email, Email = model.Email, }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { //await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false); // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); //await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); var from = $"Bug-A-Boo<{ConfigurationManager.AppSettings["emailfrom"]}>"; try { var email = new MailMessage(from, model.Email) { Subject = "Confirmation", Body = "Confirm your account<a class='btn btn-primary' href=\"" + callbackUrl + "\"> Confirm </a>", IsBodyHtml = true }; var svc = new PersonalEmailService(); await svc.SendAsync(email); ViewBag.Message = "You Must Confirm Your Email To Login"; //return RedirectToAction("StartLogin", "Account"); return(View("Info")); } catch (Exception ex) { Console.WriteLine(ex.Message); await Task.FromResult(0); } } AddErrors(result); } // If we got this far, something failed, redisplay form return(RedirectToAction("StartLogin", "Home"));; }
public ActionResult AssignDeveloper(DeveloperTickets model) { var ticket = db.Tickets.FirstOrDefault(p => p.Id == model.Id); ticket.AssigneeId = model.SelectedUser; db.SaveChanges(); var user = db.Users.Where(p => p.Id == model.SelectedUser).FirstOrDefault(); var personalEmailService = new PersonalEmailService(); var mailMessage = new MailMessage(WebConfigurationManager.AppSettings["emailto"], user.Email); mailMessage.IsBodyHtml = true; personalEmailService.Send(mailMessage); return(RedirectToAction("Index")); }
//[Authorize(Roles = "Submitter")] public ActionResult CreateAttachment(int ticketId, [Bind(Include = "Id,Description,TicketTypeId")] TicketAttachment ticketAttachment, HttpPostedFileBase image) { var tickets = db.Tickets .Where(p => p.Id == ticketId) .FirstOrDefault(); var userId = User.Identity.GetUserId(); var ProjectMangerOrDeveloperId = db.Users.Where(p => p.Id == userId).FirstOrDefault(); var projectsIds = ProjectMangerOrDeveloperId.Projects.Select(p => p.Id).ToList(); var projects = db.Tickets.Where(p => projectsIds.Contains(p.ProjectId)).ToList(); if (ModelState.IsValid) { if (image == null) { return(HttpNotFound()); } if (!ImageUploadValidator.IsWebFriendlyImage(image)) { ViewBag.ErrorMessage = "Please upload an image"; } if ((User.IsInRole("Admin")) || (User.IsInRole("Project Manager") && projects.Any(p => p.Id == ticketId)) || (User.IsInRole("Submitter") && tickets.CreaterId == userId) || (User.IsInRole("Developer") && tickets.Assignee.Id == userId)) { var fileName = Path.GetFileName(image.FileName); image.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName)); ticketAttachment.FilePath = "/Uploads/" + fileName; ticketAttachment.UserId = User.Identity.GetUserId(); ticketAttachment.Created = DateTime.Now; ticketAttachment.TicketId = ticketId; db.TicketAttachments.Add(ticketAttachment); var user = db.Users.FirstOrDefault(p => p.Id == ticketAttachment.UserId); var personalEmailService = new PersonalEmailService(); var mailMessage = new MailMessage( WebConfigurationManager.AppSettings["emailto"], user.Email); mailMessage.Body = "DB Has a new attachment"; mailMessage.Subject = "New Attachment"; mailMessage.IsBodyHtml = true; personalEmailService.Send(mailMessage); db.SaveChanges(); } else if (User.Identity.IsAuthenticated) { ViewBag.ErrorMessage = "Sorry! you are not allowed to attach document."; return(View("Details", tickets)); } return(RedirectToAction("Details", new { id = ticketId })); } return(View(ticketAttachment)); }
public Task SendAsync(IdentityMessage message) { var personalEmailService = new PersonalEmailService(); var mailMessage = new MailMessage( "*****@*****.**", message.Destination ); mailMessage.Body = message.Body; mailMessage.Subject = message.Subject; mailMessage.IsBodyHtml = true; return(personalEmailService.SendAsync(mailMessage)); }
public ActionResult CreateComment(int id, string body) { var tickets = db.Tickets .Where(p => p.Id == id) .FirstOrDefault(); var userId = User.Identity.GetUserId(); var ProjectMangerOrDeveloperId = db.Users.Where(p => p.Id == userId).FirstOrDefault(); var projectsIds = ProjectMangerOrDeveloperId.Projects.Select(p => p.Id).ToList(); var projects = db.Tickets.Where(p => projectsIds.Contains(p.ProjectId)).ToList(); if (tickets == null) { return(HttpNotFound()); } if (string.IsNullOrWhiteSpace(body)) { ViewBag.ErrorMessage = "Comment is required"; return(View("Details", tickets)); } if ((User.IsInRole("Admin")) || (User.IsInRole("Project Manager") && projects.Any(p => p.Id == id)) || (User.IsInRole("Submitter") && tickets.CreaterId == userId) || (User.IsInRole("Developer") && tickets.Assignee.Id == userId)) { var comment = new TicketComment(); comment.UserId = User.Identity.GetUserId(); comment.TicketId = tickets.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 PersonalEmailService(); var mailMessage = new MailMessage( WebConfigurationManager.AppSettings["emailto"], user.Email ); mailMessage.Body = "DB Has a new Comment"; mailMessage.Subject = "Comment"; mailMessage.IsBodyHtml = true; personalEmailService.Send(mailMessage); db.SaveChanges(); } else if (User.Identity.IsAuthenticated) { ViewBag.ErrorMessage = "Sorry!! you are not allowed to comment."; return(View("Details", tickets)); } return(RedirectToAction("Details", new { id })); }
public ActionResult AssignDevelopers(AssignTicketToDeveloper model) { var ticket = db.Tickets.FirstOrDefault(p => p.Id == model.Id); ticket.AssigneeId = model.SelectedUser; var user = db.Users.FirstOrDefault(p => p.Id == model.SelectedUser); var personalEmailService = new PersonalEmailService(); var mailMessage = new MailMessage( WebConfigurationManager.AppSettings["emailto"], user.Email ); mailMessage.Body = "You Have been assigned to new Ticket! :-)"; mailMessage.Subject = "New Assigned Developer"; mailMessage.IsBodyHtml = true; personalEmailService.Send(mailMessage); db.SaveChanges(); return(RedirectToAction("Index")); }
public IHttpActionResult Invite(InviteHouseHoldBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var userId = User.Identity.GetUserId(); if (!_db.Households.Any(p => p.Id == model.HouseHoldId && p.CreatorId == userId)) { return(BadRequest("Household not found")); } var invitedUser = _db.Users.FirstOrDefault(p => p.Email == model.Email); if (invitedUser == null) { return(BadRequest("User not found")); } //TODO: Validations // Validate if the invite has already been sent. // Validate if the user already belongs to the household. // Validate if we are not inviting ourself. var invite = new HouseHoldInvite(); invite.InvitedDate = DateTime.Now; invite.HouseHoldId = model.HouseHoldId; invite.InvitedUserId = invitedUser.Id; _db.Invites.Add(invite); _db.SaveChanges(); var emailService = new PersonalEmailService(); var emailMessage = new System.Net.Mail.MailMessage("*****@*****.**", invitedUser.Email); emailMessage.Subject = "Hey, you got a new invite :)"; emailMessage.Body = "New invite pending, please check the website to accept"; emailService.Send(emailMessage); return(Ok("Invite created sucessfully")); }
public ActionResult AssignDeveloper(AssignDevelopersTicketModel model) { var ticket = db.Tickets.FirstOrDefault(p => p.Id == model.TicketId); ticket.AssigneeId = model.SelectedDeveloperId; // Plug in your email service here to send an email. var user = db.Users.FirstOrDefault(p => p.Id == model.SelectedDeveloperId); var personalEmailService = new PersonalEmailService(); var mailMessage = new MailMessage( WebConfigurationManager.AppSettings["emailto"], user.Email ); mailMessage.Body = "DB Has Some new Changes"; mailMessage.Subject = "New Assigned Developer"; mailMessage.IsBodyHtml = true; personalEmailService.Send(mailMessage); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult CreateAttachment(int id, string description, HttpPostedFileBase image) { var attachments = db.Tickets.Where(p => p.Id == id).FirstOrDefault(); var ticketsAttachment = new TicketAttachment(); if (attachments == null) { return(HttpNotFound()); } if (ImageUploadValidator.IsWebFriendlyImage(image)) { var fileName = Path.GetFileName(image.FileName); image.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName)); ticketsAttachment.MediaURL = "/Uploads/" + fileName; } ticketsAttachment.Created = DateTime.Now; ticketsAttachment.FileName = image.FileName; ticketsAttachment.Description = description; ticketsAttachment.TicketsId = attachments.Id; ticketsAttachment.UsersId = User.Identity.GetUserId(); db.TicketAttachments.Add(ticketsAttachment); db.SaveChanges(); var devId = db.Roles.Where(p => p.Name == "Developer").Select(p => p.Id).FirstOrDefault(); if (attachments.AssignedToUser != null && attachments.AssignedToUser.Roles.Any(p => p.RoleId == devId)) { var personalEmailService = new PersonalEmailService(); var mailMessage = new MailMessage( WebConfigurationManager.AppSettings["emailto"], attachments.AssignedToUser.Email ); mailMessage.Body = "You have a attachment, please confirm it as soon as possible"; mailMessage.Subject = "New one attachment"; mailMessage.IsBodyHtml = true; personalEmailService.Send(mailMessage); } return(RedirectToAction("Details", new { id })); }
public ActionResult CreateComment(int id, string body) { var tickets = db.Tickets .Where(p => p.Id == id) .FirstOrDefault(); var useR = User.Identity.GetUserId(); if (tickets == null) { return(HttpNotFound()); } if (string.IsNullOrWhiteSpace(body)) { ViewBag.ErrorMessage = "Comment is required"; return(View("Details", tickets)); } if ((User.IsInRole("Submitter") && tickets.CreaterId == useR ) || (User.IsInRole("Developer") && tickets.AssigneeId == useR ) || (User.IsInRole("Project Manager") && tickets.Project.User.Select(p => p.Id).Contains(useR))) { var comment1 = new TicketComment(); comment1.UserId = User.Identity.GetUserId(); comment1.TicketId = tickets.Id; comment1.Created = DateTime.Now; comment1.Cpmment = body; var userid = db.Users.FirstOrDefault(c => c.Id == comment1.UserId); db.TicketComments.Add(comment1); // Plug in your email service here to send an email. var personalEmailService = new PersonalEmailService(); var mailMessage = new MailMessage( WebConfigurationManager.AppSettings["emailto"], userid.Email); mailMessage.Body = "hi"; mailMessage.Subject = "hi"; mailMessage.IsBodyHtml = true; personalEmailService.Send(mailMessage); db.SaveChanges(); } return(RedirectToAction("Details", new { id })); }
public async Task <ActionResult> ForgotPassword(ForgotPasswordViewModel model) { if (ModelState.IsValid) { var user = await UserManager.FindByNameAsync(model.Email); if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id))) { // Don't reveal that the user does not exist or is not confirmed return(View("ForgotPasswordConfirmation")); } // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id); var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>"); var from = $"BlogSite<{ConfigurationManager.AppSettings["emailfrom"]}>"; try { var email = new MailMessage(from, model.Email) { Subject = "Password", Body = "Reset password<a class='btn btn-primary' href=\"" + callbackUrl + "\"> Reset password </a>", IsBodyHtml = true }; var svc = new PersonalEmailService(); await svc.SendAsync(email); return(RedirectToAction("ForgotPasswordConfirmation")); } catch (Exception ex) { Console.WriteLine(ex.Message); await Task.FromResult(0); } } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult CreateComment(int id, string comment) { var comments = db.Tickets.Where(p => p.Id == id).FirstOrDefault(); if (comments == null) { return(HttpNotFound()); } if (string.IsNullOrWhiteSpace(comment)) { TempData["ErrorMessage"] = "Comment is empty!"; return(View("Details", new { id })); } var ticketsComment = new TicketsComment(); ticketsComment.UsersId = User.Identity.GetUserId(); ticketsComment.Created = DateTime.Now; ticketsComment.TicketsId = comments.Id; ticketsComment.Comment = comment; db.TicketsComments.Add(ticketsComment); db.SaveChanges(); var devId = db.Roles.Where(p => p.Name == "Developer").Select(p => p.Id).FirstOrDefault(); if (comments.AssignedToUser != null && comments.AssignedToUser.Roles.Any(p => p.RoleId == devId)) { var personalEmailService = new PersonalEmailService(); var mailMessage = new MailMessage( WebConfigurationManager.AppSettings["emailto"], comments.AssignedToUser.Email ); mailMessage.Body = "You have a comment, please confirm it as soon as possible"; mailMessage.Subject = "New one comment"; mailMessage.IsBodyHtml = true; personalEmailService.Send(mailMessage); } return(RedirectToAction("Details", new { id })); }
public ActionResult CreateComment(int id, string body, string UserId, TicketComment ticketComment) { if (id == 0) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var ticket = db.Tickets .Where(p => p.Id == id) .FirstOrDefault(); if (ticket == null) { return(HttpNotFound()); } if (User.Identity.IsAuthenticated) { if (User.IsInRole("Admin") || (User.IsInRole("Submitter") && ticket.CreatorId == UserId) || (User.IsInRole("Developer") && ticket.AssigneeId == UserId)) { var comment = new TicketComment(); comment.UserId = User.Identity.GetUserId(); comment.TicketId = ticket.Id; comment.Created = DateTime.Now; comment.Comment = body; db.Comments.Add(comment); db.SaveChanges(); var ticket1 = db.Tickets.Where(p => p.Id == ticketComment.TicketId).FirstOrDefault(); if (ticket1.AssigneeId != null) { var personalEmailService = new PersonalEmailService(); var mailMessage = new MailMessage(WebConfigurationManager.AppSettings["emailto"], ticket1.Assignee.Email); mailMessage.IsBodyHtml = true; personalEmailService.Send(mailMessage); } return(RedirectToAction("Details", new { id = id })); } } return(RedirectToAction("Details", new { id = id })); }
public ActionResult PMAssign(ProjectsAssign model) { var ticket = db.Tickets.FirstOrDefault(p => p.Id == model.Id); var assignedUsers = ticket.Users.ToList(); var devId = db.Roles.Where(p => p.Name == "Developer").Select(p => p.Id).FirstOrDefault(); var delUsers = assignedUsers.Where(p => p.Roles.Any(r => r.RoleId == devId)); foreach (var user in delUsers) { ticket.Users.Remove(user); } if (model.SelectedUsers != null) { foreach (var userId in model.SelectedUsers) { var user = db.Users.FirstOrDefault(p => p.Id == userId); ticket.Users.Add(user); ticket.AssignedToUserId = userId; var personalEmailService = new PersonalEmailService(); var mailMessage = new MailMessage( WebConfigurationManager.AppSettings["emailto"], user.Email ); mailMessage.Body = "Please confirm your tickect as soon as possible"; mailMessage.Subject = "You have an assigned tickect"; mailMessage.IsBodyHtml = true; personalEmailService.Send(mailMessage); } } db.SaveChanges(); return(RedirectToAction("PMIndex")); }
public ActionResult AssignDevelopers(AssinDevlViewModal model) { //STEP 1: Find the ticket. var tiket = db.Tickets.FirstOrDefault(x => x.Id == model.Id); //STEP 2: Assign the developer that the user select to the ticket. tiket.AssigneeId = model.DeveloperId; var user = db.Users.FirstOrDefault(i => i.Id == model.DeveloperId); //STEP 3: Save the ticket. var personalEmailService = new PersonalEmailService(); var mailMessage = new MailMessage( WebConfigurationManager.AppSettings["emailto"], user .Email); mailMessage.Body = "hi"; mailMessage.Subject = "hi"; mailMessage.IsBodyHtml = true; personalEmailService.Send(mailMessage); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult CreateAttachment(int id, HttpPostedFileBase image, IdentityMessage message) { var sbjl = new TicketAttachment(); var sbgl = db.TicketModels.Where(p => p.Id == id).FirstOrDefault(); if (ModelState.IsValid) { if (ImageUploadValidator.IsWebFriendlyImage(image)) { ViewBag.ErrorMessage = "Uploaded the avater is required"; } var fileName = Path.GetFileName(image.FileName); image.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName)); sbjl.FilePath = "/Uploads/" + fileName; sbjl.UserId = User.Identity.GetUserId(); sbjl.TicketId = sbgl.Id; sbjl.Created = DateTime.Now; db.TicketAttachments.Add(sbjl); var attachmentFind2 = db.Users.Where(t => t.Id == sbjl.UserId).FirstOrDefault(); var personalEmailService = new PersonalEmailService(); var mailMessage = new MailMessage( WebConfigurationManager.AppSettings["emailto"], attachmentFind2.Email ); mailMessage.Body = "Correct"; mailMessage.Subject = "Attachment"; mailMessage.IsBodyHtml = true; personalEmailService.Send(mailMessage); db.SaveChanges(); return(RedirectToAction("Details", new{ id })); } return(View(sbjl)); }