public ICommandResult Handle(CreateTimeCommand command) { command.Validate(); if (!command.IsValid) { return(new GenericCommandResult(false, "Error: ", command.Notifications)); } var time = new Time(command.Project_Id, command.User_Id, command.Started_at, command.Ended_at); _repository.Create(time); return(new GenericCommandResult(true, "Create time with success!", time)); }
public JsonResult Create([FromBody] CreateTimeCommand command, [FromServices] TimeHandler handler) { if (command is null) { return new JsonResult(NotFound()) { StatusCode = 404 } } ; try { var time = (GenericCommandResult)handler.Handle(command); if (!time.Success) { return new JsonResult(BadRequest()) { StatusCode = 400, Value = new GenericCommandResult(false, time.Message, command.Notifications) } } ; var data = (Time)time.Data; return(Json(new TimeDTO(data.Id, data.Project, data.User, data.Started_at, data.Ended_at))); } catch (Exception ex) { return(new JsonResult(BadRequest()) { StatusCode = 400, Value = new GenericCommandResult(false, ex.Message, command.Notifications) }); } }