public async Task <CommandResult> ExecuteAsync(CsmsMaterial model) { try { if (model == null || model.Id < 0 || model.Name.IsEmpty() || model.Unit.IsEmpty()) { return(CommandResult.Failed(new CommandResultError() { Code = (int)HttpStatusCode.BadRequest, Description = MessageError.SomeDataEmptyOrInvalid })); } if (model.Id == 0) { await _materialRepository.InsertAsync(model); } else { await _materialRepository.UpdateAsync(model); } return(CommandResult.SuccessWithData(model)); } catch (Exception) { return(CommandResult.Failed(new CommandResultError() { Code = (int)HttpStatusCode.InternalServerError, Description = MessageError.InternalServerError })); } }
public async Task <IActionResult> SaveMaterial(CsmsMaterial model) { var result = await _saveMaterialCommand.ExecuteAsync(model); return(StatusCode(result.GetStatusCode(), result.GetData())); }