public async Task <ToDoTask> AddTask([FromBody] AddTaskParams parameters) { try { #region validation if (parameters == null) { throw ToDoExceptions.CreateExceptionBadParam(nameof(parameters), "null", "Parameters is null"); } if (parameters.Id == 0) { throw ToDoExceptions.CreateExceptionRequiredFieldIsMissing(nameof(parameters.Id)); } if (parameters.Name == null) { throw ToDoExceptions.CreateExceptionRequiredFieldIsMissing(nameof(parameters.Name)); } #endregion return(await _postTaskService.AddTaskAsync( parameters.Id, parameters.Name, parameters.Description)); } catch (BaseException ex) { Response.StatusCode = (int)HttpStatusCode.BadRequest; // debug RedisProvider _redis = new RedisProvider(); _redis.Set <BaseException>("last-exception", ex); /// return(null); } catch (Exception ex) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return(null); } }
public async Task DeleteTask(long id) { // Todo: fix api. case: if there is nothing to delete try { if (id == 0) { throw ToDoExceptions.CreateExceptionBadParam(nameof(id), id.ToString()); } await _deleteTaskService.DeleteTask(id); } catch (BaseException ex) { Response.StatusCode = (int)HttpStatusCode.BadRequest; // debug RedisProvider _redis = new RedisProvider(); _redis.Set <BaseException>("last-exception", ex); /// } catch (Exception ex) { Response.StatusCode = (int)HttpStatusCode.BadRequest; } }