Beispiel #1
0
        public IActionResult SendEmail(Guid id)
        {
            var email = Service.GetById(id);

            if (email == null)
            {
                return(NotFound());
            }

            var result = _mailHelper.SendEmail(email).Result;

            return(Ok(result));
        }
Beispiel #2
0
        private void SendEmails(List <EmailArchieve> emails)
        {
            foreach (var email in emails)
            {
                Console.WriteLine();
                Console.WriteLine("Sending email [{0}]", email.Id);

                var result = _mailing.SendEmail(email).Result;

                Console.WriteLine("Status : {0}", email.IsSent);
                Console.WriteLine("Try Sending : {0}", email.TrySentCount);
                Console.WriteLine("Last Try Date: {0}",
                                  _common.ToLongString(email.LastTrySentDate));
                Console.WriteLine();
            }
        }
Beispiel #3
0
        public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var user = new ApplicationUser
            {
                UserName    = model.Email,
                Email       = model.Email,
                UserProfile = new UserProfile()
                {
                    Name = model.Name,
                }
            };
            var result = await userManager.CreateAsync(user, model.Password);

            if (result.Succeeded)
            {
                // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=532713
                // Send an email with this link
                //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
                //var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme);
                //await _emailSender.SendEmailAsync(model.Email, "Confirm your account",
                //    $"Please confirm your account by clicking this link: <a href='{callbackUrl}'>link</a>");
                await userManager.AddToRoleAsync(user, _config.GetConfig("user.default.role"));

                var code = await userManager.GenerateEmailConfirmationTokenAsync(user);

                var callbackUrl = Url.Action("ConfirmEmail",
                                             "Account",
                                             new { userId = user.Id, code = code },
                                             hostConfiguration.Protocol,
                                             hostConfiguration.Name);

                var additionalData = new Dictionary <string, string>()
                {
                    { "CallbackUrl", callbackUrl },
                    { "Name", model.Name },
                    { "Email", model.Email },
                    { "Password", "***" }
                };

                var subject = "You have been registered, please confirm your account";

                var email = _mailingHelper.CreateEmail(_config.GetConfig("smtp.from.email"),
                                                       model.Email,
                                                       subject,
                                                       "Emails/RegisterUser",
                                                       user,
                                                       additionalData,
                                                       null);

                var emailResult = _mailingHelper.SendEmail(email).Result;

                ViewData["EmailSent"] = emailResult.IsSent;

                return(RedirectToLocal(returnUrl));
            }
            AddErrors(result);
            return(View(model));
        }
Beispiel #4
0
        private void UpdateUser(SrfRequest item, string notes, string id, string type)
        {
            #region CreateUser
            var Candidate = _candidate.GetById(item.CandidateId);
            var AppUser   = _userManager.FindByEmailAsync(Candidate.Email).Result;

            var defaultPassword = _config.GetConfig("user.default.password");
            if (AppUser == null)
            {
                // Email not exists
                var user = new ApplicationUser()
                {
                    UserName    = Candidate.Email,
                    Email       = Candidate.Email,
                    UserProfile = new UserProfile()
                    {
                        Name              = Candidate.Name,
                        Email             = Candidate.Email,
                        UserName          = Candidate.Email,
                        IsActive          = true,
                        Roles             = "Contractor",
                        Address           = Candidate.Address,
                        Birthdate         = Candidate.DateOfBirth,
                        Description       = Candidate.Description,
                        Gender            = Candidate.Gender,
                        HomePhoneNumber   = Candidate.HomePhoneNumber,
                        MobilePhoneNumber = Candidate.MobilePhoneNumber,
                        IdNumber          = Candidate.IdNumber,
                        IsBlacklist       = false,
                        IsTerminate       = false
                    }
                };
                var result = _userManager.CreateAsync(user, defaultPassword).Result;
                if (result.Succeeded)
                {
                    List <string> Roles = new List <string> {
                        "Contractor"
                    };
                    result = _userManager.AddToRolesAsync(user, Roles).Result;
                    if (result.Succeeded)
                    {
                        var code        = _userManager.GenerateEmailConfirmationTokenAsync(user).Result;
                        var callbackUrl = Url.Action("ConfirmEmail",
                                                     "Account",
                                                     new { userId = user.Id, code = code, area = "" },
                                                     _hostConfiguration.Protocol,
                                                     _hostConfiguration.Name);

                        var additionalData = new Dictionary <string, string>()
                        {
                            { "CallbackUrl", callbackUrl },
                            { "Name", Candidate.Name },
                            { "Email", Candidate.Email },
                            { "Password", defaultPassword }
                        };

                        var subject = "You have been registered, please confirm your account, Leave to be taken cannot compensate";

                        var email = _mailingHelper.CreateEmail(_config.GetConfig("smtp.from.email"),
                                                               Candidate.Email,
                                                               subject,
                                                               "Emails/RegisterUser",
                                                               user,
                                                               additionalData,
                                                               null);

                        // Send Email Confirmation To User
                        var emailResult = _mailingHelper.SendEmail(email).Result;

                        // Update Candidate
                        Candidate.IsCandidate  = false;
                        Candidate.IsContractor = true;
                        Candidate.IsUser       = true;
                        Candidate.Account      = user.UserProfile;
                        _candidate.Update(Candidate);
                        _srf.SetActive(item.Id, Candidate.Id, user.UserProfile.Id);
                    }
                }
            }
            else
            {
                if (item.Type == SrfType.New)
                {
                    // Current email registered
                    var UserProfile = _profileService.GetByUserId(AppUser.Id);
                    var callbackUrl = Url.Action("Index",
                                                 "Home",
                                                 new { area = "Admin" },
                                                 _hostConfiguration.Protocol,
                                                 _hostConfiguration.Name);

                    var additionalData = new Dictionary <string, string>()
                    {
                        { "CallbackUrl", callbackUrl },
                        { "Name", Candidate.Name },
                        { "Email", Candidate.Email },
                        { "Password", defaultPassword }
                    };

                    var subject = "You have been registered, please confirm your account, Leave to be taken cannot compensate";

                    var email = _mailingHelper.CreateEmail(_config.GetConfig("smtp.from.email"),
                                                           Candidate.Email,
                                                           subject,
                                                           "Emails/RegisterUser",
                                                           AppUser,
                                                           additionalData,
                                                           null);

                    // Send Email Confirmation To User
                    var emailResult = _mailingHelper.SendEmail(email).Result;

                    // Update User Profile
                    UserProfile up = _profileService.GetById(UserProfile.Id);
                    up.Name              = Candidate.Name;
                    up.Email             = Candidate.Email;
                    up.UserName          = Candidate.Email;
                    up.IsActive          = true;
                    up.Address           = Candidate.Address;
                    up.Birthdate         = Candidate.DateOfBirth;
                    up.Description       = Candidate.Description;
                    up.Gender            = Candidate.Gender;
                    up.HomePhoneNumber   = Candidate.HomePhoneNumber;
                    up.MobilePhoneNumber = Candidate.MobilePhoneNumber;
                    up.IdNumber          = Candidate.IdNumber;
                    up.IsBlacklist       = false;
                    up.IsTerminate       = false;
                    _profileService.Update(up);

                    // Update Candidate
                    Candidate.IsCandidate  = false;
                    Candidate.IsContractor = true;
                    Candidate.IsUser       = true;
                    Candidate.Account      = UserProfile;
                    _candidate.Update(Candidate);
                    _srf.SetActive(item.Id, Candidate.Id, UserProfile.Id);
                }
                else
                {
                    var UserProfile = _profileService.GetByUserId(AppUser.Id);
                    _srf.SetActive(item.Id, Candidate.Id, UserProfile.Id);
                }
            }

            if (User.IsInRole("Service Coordinator"))
            {
                var Number = _srf.GenerateNumnber();
                item.Number = Number;
            }

            // Update General Srf
            item.NotesFirst           = notes;
            item.Status               = SrfStatus.Waiting;
            item.ApproveStatusSix     = SrfApproveStatus.Approved;
            item.DateApproveStatusSix = DateTime.Now;
            _srf.Update(item);

            // Send Notification To LM
            SendNotif(id, item.ApproveOneId, "Service Request Form is approved (Escalation) by " + _userHelper.GetLoginUser(User).Name + " " + type, "your Service Request Form is approved (Escalation) by " + _userHelper.GetLoginUser(User).Name + " " + type, NotificationInboxStatus.Approval, notes);
            #endregion
        }