コード例 #1
0
        public async Task <IActionResult> Post(string values)
        {
            var model = new SalesPerson();

            JsonConvert.PopulateObject(values, model);

            if (!TryValidateModel(model))
            {
                return(BadRequest(GetFullErrorMessage(ModelState)));
            }

            var user = new ApplicationUser()
            {
                UserName = model.EMail, Email = model.EMail
            };

            IdentityResult result = await _accountManager.CreateAccountAsync(user, Enum.EnumApplicationRole.Partner);

            if (result.Succeeded)
            {
                await _accountManager.SendEmailConfirmationAsync(user, this.Request, this.Url);

                model.ApplicationUserId = user.Id;
                _salesRepo.Add(model);

                return(_uow.Commit() ? Ok() : StatusCode(Microsoft.AspNetCore.Http.StatusCodes.Status500InternalServerError));
            }
            else
            {
                _accountManager.AddModelStateErrors(this.ModelState, result);
                return(BadRequest(GetFullErrorMessage(this.ModelState)));
            }
        }
コード例 #2
0
        public async Task <ActionResult <SalesPersons> > PostSalesPersons(SalesPersons salesPersons)
        {
            await _salesPersonRepository.Add(salesPersons);

            return(CreatedAtAction("GetSalesPersons", new { id = salesPersons.SalesPersonsId }, salesPersons));
        }