public HttpResponseMessage Create([FromBody] ProfileViewModel model) { try { if (model == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid model")); } if (string.IsNullOrEmpty(model.Code)) { return(Request.CreateResponse(HttpStatusCode.BadRequest, $"Invalid profile code.")); } if (profileBusiness.GetByCode(model.Code) != null) { return(Request.CreateResponse(HttpStatusCode.BadRequest, $"Profile code {model.Code} already exists.")); } var profileEntity = mapper.MapFromModelToEntity(model); profileBusiness.Create(profileEntity); var ProfileViewModel = profileBusiness.GetByCode(model.Code); return(Request.CreateResponse(HttpStatusCode.Created, ProfileViewModel)); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
public IActionResult Post([FromBody] Profile profile) { if (profile == null) { return(BadRequest()); } return(new ObjectResult(_profileBusiness.Create(profile))); }