示例#1
0
        public async Task <DataTransferObjectBase> ResetPassword([FromBody] UserDto user)
        {
            var applicationUser = _userManager.Users.FirstOrDefault(u => u.Id == user.Id);

            if (user == null)
            {
                return(new DataTransferObjectBase
                {
                    Success = false,
                    ErrorMessage = "User is not found"
                });
            }
            string resetToken = await _userManager.GeneratePasswordResetTokenAsync(applicationUser);

            string newPassword = GeneratePassword();
            var    result      = await _userManager.ResetPasswordAsync(applicationUser, resetToken, newPassword);

            string requestIp = Request.HttpContext.Connection.RemoteIpAddress.ToString();
            IEmailMessageBuilder messageBuilder = new ResetPasswordEmailBuilder(requestIp, newPassword);
            IEmailSender         sender         = new NotificationEmailSender();
            string subject = messageBuilder.BuildSubject();
            string body    = messageBuilder.BuildBody();

            await sender.SendEmailAsync(applicationUser.Email, subject, body);

            return(new DataTransferObjectBase());
        }
        public async Task <ActionResult> Create([Bind(Include = "TicketId,Body,FileUrl")] TicketComment ticketComment, HttpPostedFileBase uploadedFile)
        {
            if (ModelState.IsValid)
            {
                //rule out empty files and file types we don't want
                if (uploadedFile.IsAllowedFileType() == true)
                {
                    if (uploadedFile.ContentType.In("image/bmp", "image/gif", "image/jpeg", "image/png") != true)
                    {
                        string fileName = Path.GetFileName(uploadedFile.FileName);
                        uploadedFile.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName));
                        ticketComment.FileUrl = "/Uploads/" + fileName;
                    }
                    // now we validate images are web-friendly
                    else if ((uploadedFile.ContentType.In("image/bmp", "image/gif", "image/jpeg", "image/png") && (FileUploadValidator.IsWebFriendlyImage(uploadedFile) == true)))
                    {
                        string fileName = Path.GetFileName(uploadedFile.FileName);
                        uploadedFile.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName));
                        ticketComment.FileUrl = "/Uploads/" + fileName;
                    }
                    else
                    {
                        ticketComment.FileUrl = null;
                    }
                }

                //sent a ticket noti
                if (ticketComment.Ticket.AssignedUserId != "1712e9df-c37b-402d-9d27-d8568f975b79" && User.Identity.GetUserId() != ticketComment.Ticket.AssignedUserId)
                {
                    NotificationEmailSender nes     = new NotificationEmailSender();
                    TicketNotification      tktNoti = new TicketNotification();
                    tktNoti.TicketId = ticketComment.TicketId;
                    tktNoti.UserId   = ticketComment.Ticket.AssignedUserId;

                    var    callbackUrl = Url.Action("Details", "TicketComments", new { id = ticketComment.Id }, protocol: Request.Url.Scheme);
                    string targetEmail = User.Identity.Name;

                    await nes.SendCommentCreateNoti(callbackUrl, targetEmail);

                    db.TicketNotifications.Add(tktNoti);
                }

                ticketComment.Created = DateTimeOffset.Now;
                ticketComment.UserId  = User.Identity.GetUserId();
                ticketComment.Closed  = false;

                db.TicketComments.Add(ticketComment);
                db.SaveChanges();

                var tkt = db.TicketComments.Include("Ticket").FirstOrDefault(tc => tc.Id == ticketComment.Id);
                return(RedirectToAction("Details", "Tickets", new { id = tkt.Ticket.Id }));
            }

            ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title", ticketComment.TicketId);
            ViewBag.UserId   = new SelectList(db.Users, "Id", "FirstName", ticketComment.UserId);
            return(View(ticketComment));
        }
        private void SendNotification(Notes @event, List <string> emails)
        {
            IEmailMessageBuilder messageBuilder = new EventNotificationBuilder(@event);
            string message = messageBuilder.BuildBody();
            string subject = messageBuilder.BuildSubject();

            IEmailSender sender = new NotificationEmailSender();

            foreach (string email in emails)
            {
                sender.SendEmailAsync(email, subject, message);
            }
        }
示例#4
0
        public async Task <ActionResult> ContactSend([Bind(Include = "FromName,FromEmail,Subject,Body,Dummy")] ContactMsg contactMsg)
        {
            if (ModelState.IsValid && String.IsNullOrEmpty(contactMsg.Dummy))
            {
                NotificationEmailSender nes = new NotificationEmailSender();

                await nes.SendContactFormNoti(contactMsg);

                return(View("ContactConfirmation"));
            }
            else
            {
                return(View("Index"));
            }
        }
        public async Task <bool> FinishEmployeeContract([FromBody] EmailFormDTO emailSource)
        {
            try
            {
                string emailHtmlTemplate = System.IO.File.ReadAllText("EmailTemplates\\mailTemplate.html");

                string emailResponseTemplate = System.IO.File.ReadAllText("EmailTemplates\\responseTemplate.html");


                string emailBody = emailHtmlTemplate.Replace("{company}", emailSource.Company)
                                   .Replace("{email}", emailSource.Email)
                                   .Replace("{name}", emailSource.Name)
                                   .Replace("{phone}", emailSource.Phone)
                                   .Replace("{text}", emailSource.Text);

                string emailSubject = $@"Nowa wiadomość ze strony: {emailSource.Subject}";

                string responseBody = emailResponseTemplate.Replace("{text}", "Otrzymaliśmy Twoją wiadomość. Dostarczymy odpowiedź w ciągu 24 godzin!");

                string responseSubject = "BWG | Otrzymaliśmy Twoją wiadomość ze strony bwg.com.pl";

                NotificationEmailSender emailSender = new NotificationEmailSender();

                await emailSender.SendEmailAsync("*****@*****.**", emailSubject, emailBody);

                await emailSender.SendEmailAsync("*****@*****.**", emailSubject, emailBody);

                await emailSender.SendEmailAsync(emailSource.Email, responseSubject, responseBody);


                return(true);
            }
            catch (Exception)
            {
                //todo: add logging
                return(false);
            }
        }
        public async void NotifyContragents([FromBody] OfferNotificationRequest request)
        {
            IRepository <AspNetUsers> repository      = new ContragentUsersRepository();
            IEnumerable <AspNetUsers> contragentUsers = request.ToAll ?
                                                        repository.Get() :
                                                        repository.Get(c => request.ContragentsIds.Contains(c.ContragentId ?? 0));

            IRepository <Offer> offersRepository = new OffersRepository();
            Offer offer = offersRepository.Get(request.OfferId);

            string offerUrl = $"{Request.Scheme}://{Request.Host}/Offers#/off_edit/{request.OfferId}";

            IEmailMessageBuilder messageBuilder = new OfferNotifyMessageBuilder(offer, offerUrl);
            string subject = messageBuilder.BuildSubject();
            string message = messageBuilder.BuildBody();

            IEmailSender sender = new NotificationEmailSender();

            foreach (AspNetUsers user in contragentUsers)
            {
                await sender.SendEmailAsync(user.Email, subject, message);
            }
        }
示例#7
0
        public bool ChangeEmploymentRequestStatus([FromBody] EmploymentRequestDto employmentRequestDto)
        {
            try
            {
                var    employee        = new Employees();
                var    contragent      = new Contragent();
                var    offer           = new Offer();
                var    responsibleUser = new AspNetUsers();
                string status;

                using (DB_A12601_bielkaContext context = new DB_A12601_bielkaContext())
                {
                    EmploymentRequests employmentRequest =
                        context.EmploymentRequests.FirstOrDefault(e => e.EtrOfrId == employmentRequestDto.OfferId && e.EtrEmpId == employmentRequestDto.EmployeeId && e.EtrAuditRd == null);

                    if (employmentRequest == null)
                    {
                        return(false);
                    }

                    employmentRequest.EtrAuditMd = DateTime.UtcNow;
                    employmentRequest.EtrAuditMu = User.GetUserId();
                    employmentRequest.EtrStatus  = employmentRequestDto.Status;

                    status = employmentRequestDto.Status == 1 ? "Accepted" : "Rejected";

                    employee        = context.Employees.FirstOrDefault(c => c.EmpId == employmentRequest.EtrEmpId);
                    contragent      = context.Contragents.FirstOrDefault(c => c.CgtId == employee.EmpCtgId);
                    offer           = context.Offers.FirstOrDefault(o => o.OfrId == employmentRequest.EtrOfrId);
                    responsibleUser = context.AspNetUsers.FirstOrDefault(u => u.Id == contragent.CgtResponsibleUser);

                    if (employmentRequest.EtrStatus == 1)
                    {
                        employee.EmpCltId = employmentRequest.EtrCltId;
                        employee.EmpOffId = employmentRequest.EtrOfrId;
                    }

                    if (employmentRequest.EtrStatus == 2)
                    {
                        employee.EmpCltId = null;
                        employee.EmpOffId = null;
                    }


                    context.SaveChanges();
                }

                IEmailMessageBuilder bodyBuilder = new ChangePimpStatusBodyBuilder(new EmployeeDto(employee), new ContragentDto(contragent), new OfferDto(offer), status);
                string emailBody    = bodyBuilder.BuildBody();
                string emailSubject = bodyBuilder.BuildSubject();

                NotificationEmailSender emailSender = new NotificationEmailSender();
                if (responsibleUser.Email != null)
                {
                    //       await emailSender.SendEmailAsync(responsibleUser.Email, emailSubject, emailBody);
                }
                //   await emailSender.SendEmailAsync("*****@*****.**", emailSubject, emailBody);


                return(true);
            }
            catch (Exception)
            {
                //todo: add logging
                return(false);
            }
        }