示例#1
0
        // POST tables/Inspector
        public async Task <IHttpActionResult> PostInspector(Inspector item)
        {
            var exist = await _authManager.FindByEmailAsync(item.Email);

            if (exist != null)
            {
                Debug.WriteLine("User email Bestaat al");
                return(null);
            }

            if (_geodanHelper.Error == null)
            {
                var result = await _geodanHelper.GetDocByAdres(null, null, item.HouseNumber, item.PostalCode);

                item.GeodanAdresId = result.id;
                item.Locx          = result.location.X;
                item.Locy          = result.location.Y;
            }
            else
            {
                item.GeodanAdresId = "InvalidID";

                item.Locx = 1.0;
                item.Locy = 1.0;
            }

            item.UserAccount = new UserAccount {
                UserName = item.Email, Email = item.Email, PhoneNumber = item.Phone
            };
            await _authManager.CreateAsync(item.UserAccount, "password");

            await _authManager.AddToRoleAsync(item.UserAccount.Id, "Inspector");

            Inspector current = await InsertAsync(item);

            await _emailService.SendChangePasswordMailAsync(item);

            return(CreatedAtRoute("Tables", new { id = current.Id }, current));
        }