public async Task <IHttpActionResult> Delete(long id) { try { logger.Debug("Delete - Id: {0}", id); var result = await this.service.Delete(id); logger.Info(result); if (!result.Succeeded) { return(base.GetErrorResult(result)); } var resultSaveChanges = await this.service.SaveChangesAsync(ServiceChangeCommentBuilder.GetDeleteComment <Usuario>(result.Result)); logger.Info(resultSaveChanges); if (resultSaveChanges.Succeeded) { return(StatusCode(HttpStatusCode.NoContent)); } else { return(base.GetErrorResult(resultSaveChanges)); } } catch (Exception ex) { logger.Error(ex); return(InternalServerError(ex)); } }
public async Task <IHttpActionResult> Put(long id, PutUsuarioModel model) { try { logger.Debug("Put - Id: {0} - Model: {1}", id, model); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var entity = base.ModelMapper.Map <Usuario>(model); var result = await this.service.Update(id, entity); logger.Info(result); if (!result.Succeeded) { return(base.GetErrorResult(result)); } var resultSaveChanges = await this.service.SaveChangesAsync(ServiceChangeCommentBuilder.GetUpdateComment <Usuario>(result.Result)); logger.Info(resultSaveChanges); if (resultSaveChanges.Succeeded) { return(StatusCode(HttpStatusCode.NoContent)); } else { return(base.GetErrorResult(resultSaveChanges)); } } catch (Exception ex) { logger.Error(ex); return(InternalServerError(ex)); } }
public async Task <IHttpActionResult> Post(PostUsuarioModel model) { try { logger.Debug("Post", model); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var entity = base.ModelMapper.Map <Usuario>(model); var result = this.service.Add(entity); logger.Info(result); if (!result.Succeeded) { return(base.GetErrorResult(result)); } var resultSaveChanges = await this.service.SaveChangesAsync(ServiceChangeCommentBuilder.GetCreateComment <Usuario>()); logger.Info(resultSaveChanges); if (resultSaveChanges.Succeeded) { return(CreatedAtRoute("DefaultApi", new { id = result.Result.Id }, base.ModelMapper.Map <UsuarioModel>(result.Result))); } else { return(base.GetErrorResult(resultSaveChanges)); } } catch (Exception ex) { logger.Error(ex); return(InternalServerError(ex)); } }