コード例 #1
0
        public async Task <IHttpActionResult> CreateUserAsync(UserCreateDto model)
        {
            User newUser;

            if (model == null)
            {
                ModelState.AddModelError("model", new ArgumentNullException(nameof(model)));
            }
            model.RepeatPassword = model.NewPassword;

            model.Roles.Add("deliverypartner");

            if (ModelState.IsValid == false)
            {
                return(BadRequest(ModelState));
            }

            newUser = await userRepo.CreateAsync(model.Email, model.Email, model.FirstName,
                                                 model.NewPassword, 0, model.LastName, model.CompanyFK);

            #region Add user to company
            umCompanyRepo.AddUserToCompanies(model.UserCompanies, newUser.Id);
            umCompanyRepo.SaveChanges();
            #endregion

            #region Send one time code for initial change password
            var userCode = userCodeRepo.Create(new UserCode()
            {
                UserK = newUser.Id
            });
            userCodeRepo.SaveChanges();
            string code = userCode.Code;

            var      adminSecurity = adminSecurityService.GetAdministrationSecurity();
            EmailDto emaildto      = new EmailDto()
            {
                EmailBody      = String.Format("Hi {0} {1}. You have been added as a new user to siteTRAX Evolution. <br/><br/> Your Onetime code is: <b>{2}</b> <br/> This Onetime code is valid until: <b>{3}</b> at which time it will expire and a new one code will be required to be requested. <br/><br/> To enter your onetime code. Click on \"Forget my password\" then click on \"I have a onetime code\" <br/><br/>If you did not request this password reset, please ignore this message. <br/> Do not reply to this email message as the mail box is un-monitored.", newUser.FirstName, newUser.LastName, userCode.Code, userCode.ExpirationDateUtc.ToLocalTime().ToString("dd-MMMM-yyyy hh:mm tt")),
                EmailSubject   = "New User - siteTRAX Evolution",
                EmailSender    = "*****@*****.**",
                EmailRecipient = newUser.Email
            };

            CustomEmail.SendPasswordEmail(adminSecurity.MailerServer, adminSecurity.MailerServerPort.Value, adminSecurity.MailerUsername, adminSecurity.MailerPassword, adminSecurity.PasswordResetEmail, newUser.Email, emaildto.EmailSubject, emaildto.EmailBody);
            #endregion



            //await userRepo.AssignRolesAsync(newUser, model.Roles.ToArray());

            userRepo.SaveChanges();

            return(Ok(newUser));
        }
コード例 #2
0
        public new IHttpActionResult CreateOrUpdate([FromBody] UMCompany model)
        {
            if (model == null)
            {
                return(BadRequest("Company must be provided"));
            }

            UMCompany company = umcompanyService.Read(model.UMCompanyK);

            if (company == null)
            {
                company = umcompanyService.Create(model);
            }
            else
            {
                umcompanyService.Update(company.UMCompanyK, model);
            }

            umcompanyService.SaveChanges();
            return(Ok());
        }