Esempio n. 1
0
        public async Task <IActionResult> UpdateUser(string id, [FromBody] AppUserResource appuserResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var appuser = await repository.GetUserWithAddress(id);

            if (appuser == null)
            {
                return(NotFound());
            }

            mapper.Map(appuserResource, appuser);
            await unitOfWork.CompleteAsync();

            return(Ok(mapper.Map <AppUser, AppUserResource>(appuser)));
        }
Esempio n. 2
0
        public async Task <Object> Register([FromBody] AppUserResource model)
        {
            model.Role = "Customer";

            var appUser = this.mapper.Map <AppUserResource, AppUser>(model);

            try
            {
                var result = await this.userManager.CreateAsync(appUser, model.Password);

                await this.userManager.AddToRoleAsync(appUser, model.Role);

                return(Ok(result));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> CreateUser([FromBody] AppUserResource appuserResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var appuser = mapper.Map <AppUserResource, AppUser>(appuserResource);

            try
            {
                var result = await this.userManager.CreateAsync(appuser, appuserResource.Password);

                return(Ok(result));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }