public async Task <IActionResult> CreateAsync([FromBody] UserModel value) { AppUser createVariable; createVariable = Mapper.Map(value); try { await Arepo.AddUserAsync(createVariable); } catch (Exception e) { logger.Error(e, e.ToString()); return(StatusCode(StatusCodes.Status400BadRequest)); } try { await Arepo.SaveAsync(); } catch (Exception e) { logger.Error(e, e.ToString()); return(StatusCode(StatusCodes.Status500InternalServerError)); } return(CreatedAtRoute("GetUser", new { username = value.Username }, value)); }
public async Task <IActionResult> PutAsync(string username, [FromBody] UserModel value) { AppUser updateVariable; if (!username.Equals(value.Username)) { return(StatusCode(StatusCodes.Status400BadRequest)); } if (!(User.Identity.Name.Equals(username) || User.IsInRole("admin"))) { return(StatusCode(403));//Forbidden } updateVariable = Mapper.Map(value); try { Arepo.UpdateUser(updateVariable); } catch (Exception e) { logger.Error(e, e.ToString()); return(StatusCode(StatusCodes.Status400BadRequest)); } try { await Arepo.SaveAsync(); } catch (Exception e) { logger.Error(e, e.ToString()); return(StatusCode(StatusCodes.Status500InternalServerError)); } return(StatusCode(StatusCodes.Status204NoContent)); }