Ejemplo n.º 1
0
        public void SendWelcomeEmail(UserCreateDto dto)
        {
            try
            {
                var user = new User
                {
                    FirstName = dto.FirstName,
                    LastName  = dto.LastName,
                    Email     = dto.Email,
                    Username  = dto.Username
                };

                var generateEmail = new GenerateEmailDto
                {
                    UrlAdress     = _urlAdress + "/signin?",
                    EmailMainText = "You are currently registered using",
                    ObjectId      = 0,
                    Subject       = "Welcome"
                };

                var emailModel = _generateEmailWrapper.GenerateEmail(generateEmail, user);
                _emailWrapper.SendEmail(emailModel);
            }
            catch
            {
                throw new ValidationException("Sorry, unexpected error.");
            }
        }
Ejemplo n.º 2
0
        public void sendRestoreEmail(string email)
        {
            var repo = _contextManager.CreateRepositiry <IUserRepo>();
            var user = repo.GetUserByEmail(email);

            if (user == null)
            {
                throw new ValidationException("Incorrect email combination");
            }

            if (user.isSocialNetworks)
            {
                throw new ValidationException("You have already registered via Social Networks");
            }

            var generateEmail = new GenerateEmailDto
            {
                UrlAdress     = _urlAdress + "/resetpassword?",
                EmailMainText = "Password recovery",
                ObjectId      = 0,
                Subject       = "Password recovery"
            };

            var emailModel = _generateEmailWrapper.GenerateEmail(generateEmail, user);

            _emailWrapper.SendEmail(emailModel);
        }
Ejemplo n.º 3
0
        public string AppointUserAsAdmin(CompanyTreatmentUsersModel model)
        {
            _subscriptionService.CheckSubscription(model.CompanyId);
            var repoComp = _contextManager.CreateRepositiry <ICompanyRepo>();
            var company  = repoComp.GetById(model.CompanyId);

            if (company == null)
            {
                throw new ValidationException("Company not found.");
            }

            var userError = "Something wrong with this email(s):";

            foreach (string email in model.Email)
            {
                var repoUser = _contextManager.CreateRepositiry <IUserRepo>();
                var user     = repoUser.GetUserByEmail(email);
                if (!(user == null))
                {
                    var repo        = _contextManager.CreateRepositiry <ICompanyUserLinkRepo>();
                    var companyUser = repo.GetRecordByCompanyAndUser(user.Id, model.CompanyId);

                    if (!(companyUser == null))
                    {
                        companyUser.UserCompanyRole = (int)Model.Enums.CompanyUserRoleEnum.Admin;
                        _contextManager.Save();

                        var generateEmail = new GenerateEmailDto
                        {
                            UrlAdress     = _urlAdress + "/company/" + model.CompanyId + "?",
                            EmailMainText = "Congratulations, you are Admin of " + company.Name + "! Now you can invite people to the company and create events.",
                            ObjectId      = model.CompanyId,
                            Subject       = "Company"
                        };
                        var emailModel = _generateEmailWrapper.GenerateEmail(generateEmail, user);
                        _emailWrapper.SendEmail(emailModel);
                    }
                    else
                    {
                        userError = userError + " " + email;
                    }
                }
                else
                {
                    userError = userError + " " + email;
                }
            }
            if (userError == "Something wrong with this email:")
            {
                return("Users are successfully assigned");
            }
            else
            {
                return(userError);
            }
        }
Ejemplo n.º 4
0
        public async Task SubscriptionEmail()
        {
            var repo           = _contextManager.CreateRepositiry <ICompanySubRepo>();
            var listCompanySub = repo.GetListOfExpiringSubs();

            foreach (var oneCompSub in listCompanySub)
            {
                var generateEmail = new GenerateEmailDto
                {
                    UrlAdress     = _urlAdress + "/company/" + oneCompSub.CompanyId,
                    EmailMainText = "Your subscription to " + oneCompSub.Company.Name + " will expire in 5 days",
                    ObjectId      = 0,
                    Subject       = "Sudscription"
                };

                var emailModel = _generateEmailWrapper.GenerateEmail(generateEmail, oneCompSub.User);
                _emailWrapper.SendEmail(emailModel);
            }
        }
Ejemplo n.º 5
0
        public void SendEmailToUsers(int EventId, string subject, string mainMassage)
        {
            var eventRepo = _contextManager.CreateRepositiry <IEventRepo>();
            var getEvent  = eventRepo.GetById(EventId);

            _subscriptionService.CheckSubscription(getEvent.CompanyId);

            if (getEvent == null)
            {
                throw new ValidationException("Event not found");
            }

            var repo      = _contextManager.CreateRepositiry <IEventUserLinkRepo>();
            var data      = repo.GetAll(x => x.EventId == EventId);
            var listUsers = repo.GetAllUsers(EventId);

            if (listUsers == null)
            {
                throw new ValidationException("Users not found in this event");
            }

            var generateEmail = new GenerateEmailDto
            {
                UrlAdress     = _urlAdress + "/event/" + EventId + "?",
                EmailMainText = mainMassage,
                ObjectId      = EventId,
                Subject       = subject
            };

            listUsers.Select(x => x.User);

            foreach (EventUserLink user in listUsers)
            {
                Thread thread = new Thread(() => _emailWrapper.SendEmail(_generateEmailWrapper.GenerateEmail(generateEmail, user.User)));
                thread.Start();
            }
        }