示例#1
0
        // POST tables/User
        public async Task <IHttpActionResult> PostUser(User item)
        {
            // role toevoegen
            User itemin = item;

            itemin.UserAccount = new UserAccount();

            itemin.UserAccount.UserName    = item.Email;
            itemin.UserAccount.Email       = item.Email;
            itemin.UserAccount.PhoneNumber = item.Phone;
            itemin.Email     = item.Email;
            itemin.BirthDate = item.BirthDate;
            itemin.FirstName = item.FirstName;
            itemin.LastName  = item.LastName;
            itemin.Phone     = item.Phone;
            itemin.Gender    = item.Gender;
            itemin.Role      = item.Role;
            var result = await _authManager.CreateAsync(itemin.UserAccount, "password");

            string rol = item.Role.ToString();
            await _authManager.AddToRoleAsync(item.UserAccount.Id, rol);

            User current = await InsertAsync(itemin);

            return(CreatedAtRoute("Tables", new { id = current.Id }, current));
        }
示例#2
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));
        }