Esempio n. 1
0
        public async Task <HttpResponseMessage> CreateOwner([FromBody] OwnerModel model)
        {
            if (model == null || string.IsNullOrEmpty(model.Email) ||
                (string.IsNullOrEmpty(model.FirstName) && string.IsNullOrEmpty(model.LastName)))
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
            //new user
            if (model.Id < 0)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var createResult = await UserManager.CreateAsync(user, _tempPassword);

                //no matter whether it is successful or not
                var userId = await _adminManager.CheckUserExistence(model.Email);

                if (userId < 0)
                {
                    return(Request.CreateResponse(HttpStatusCode.InternalServerError));
                }
                model.Id = userId;
            }

            var result = await _adminManager.CreateOwner(model);

            if (result)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, model));
            }
            return(Request.CreateResponse(HttpStatusCode.BadRequest));
        }