public Results.GenericResult <TodoDTO> Post([FromBody] TodoDTO model) { var result = new Results.GenericResult <TodoDTO>(); var validatorResult = validator.Validate(model); if (validatorResult.IsValid) { try { result.Result = appService.Create(model); result.Success = true; Response.StatusCode = (int)HttpStatusCode.Created; } catch (Exception ex) { Response.StatusCode = (int)HttpStatusCode.InternalServerError; result.Errors = new string[] { ex.Message }; } } else { Response.StatusCode = (int)HttpStatusCode.BadRequest; result.Errors = validatorResult.GetErrors(); } return(result); }
public Results.GenericResult Put(int id, [FromBody] TodoDTO model) { var result = new Results.GenericResult(); var validatorResult = validator.Validate(model); if (validatorResult.IsValid) { try { result.Success = appService.Update(model) != null; if (!result.Success) { throw new Exception($"Todo {id} can't be updated"); } } catch (Exception ex) { Response.StatusCode = (int)HttpStatusCode.InternalServerError; result.Errors = new string[] { ex.Message }; } } else { Response.StatusCode = (int)HttpStatusCode.BadRequest; result.Errors = validatorResult.GetErrors(); } return(result); }
public Results.GenericResult Put(int id, [FromBody] TodoDto model) { var result = new Results.GenericResult(); var validatorResult = validator.Validate(model); if (validatorResult.IsValid) { try { result.Success = appService.Update(model); if (!result.Success) { throw new Exception($"Todo {id} can't be updated"); } } catch (Exception ex) { result.Errors = new string[] { ex.Message }; } } else { result.Errors = validatorResult.GetErrors(); } return(result); }
public Results.GenericResult <TodoDto> Post([FromBody] TodoDto model) { var result = new Results.GenericResult <TodoDto>(); var validatorResult = validator.Validate(model); if (validatorResult.IsValid) { try { result.Result = appService.Create(model); result.Success = true; } catch (Exception ex) { result.Errors = new string[] { ex.Message }; } } else { result.Errors = validatorResult.GetErrors(); } return(result); }
public Results.GenericResult Delete(int id) { var result = new Results.GenericResult(); try { result.Sucess = appServices.Delete(id); } catch (Exception ex) { result.Errors = new string[] { ex.Message }; } return(result); }
public Results.GenericResult <TodoDto> Get(int id) { var result = new Results.GenericResult <TodoDto>(); try { result.Result = appServices.GetById(id); result.Sucess = true; } catch (Exception ex) { result.Errors = new string[] { ex.Message }; } return(result); }
public Results.GenericResult <IEnumerable <TodoDto> > Get([FromQuery] TodoFilterDto filterDto) { var result = new Results.GenericResult <IEnumerable <TodoDto> >(); try { result.Result = appServices.List(filterDto); result.Sucess = true; } catch (Exception ex) { result.Errors = new string[] { ex.Message }; } return(result); }
public Results.GenericResult <TodoDTO> Get(int id) { var result = new Results.GenericResult <TodoDTO>(); try { result.Result = appService.GetById(id); result.Success = true; } catch (Exception ex) { Response.StatusCode = (int)HttpStatusCode.InternalServerError; result.Errors = new string[] { ex.Message }; } return(result); }
public Results.GenericResult Delete(int id) { var result = new Results.GenericResult(); try { result.Success = appService.Delete(id); if (!result.Success) { throw new Exception($"Todo {id} can't be deleted"); } } catch (Exception ex) { result.Errors = new string[] { ex.Message }; } return(result); }
public Results.GenericResult Delete(int id) { var result = new Results.GenericResult(); try { result.Success = appService.Delete(id); if (!result.Success) { throw new Exception($"Todo {id} can't be deleted"); } } catch (Exception ex) { Response.StatusCode = (int)HttpStatusCode.InternalServerError; result.Errors = new string[] { ex.Message }; } return(result); }
public Results.GenericResult Put([FromBody] TodoDto model) { var result = new Results.GenericResult(); var validationResul = validator.Validate(model); if (validationResul.IsValid) { try { result.Sucess = appServices.Update(model); } catch (Exception ex) { result.Errors = new string[] { ex.Message }; } } else { result.Errors = validationResul.GetErrors(); } return(result); }