public async Task <APIResult> Get(int id) { return(new APIResult() { Result = 0, Data = await pesticideQueries.GetById(id) }); }
public override async Task <int> HandleCommand(DeleteCommand request, CancellationToken cancellationToken) { var pesticide = await pesticideQueries.GetById(request.Id); if (pesticide == null) { throw new BusinessException("Pesticide.NotExisted"); } var rs = -1; using (var conn = DALHelper.GetConnection()) { conn.Open(); using (var trans = conn.BeginTransaction()) { try { pesticide.IsDeleted = true; pesticide = UpdateBuild(pesticide, request.LoginSession); if (await pesticideRepository.Update(pesticide) > 0) { rs = 0; } } finally { if (rs == 0) { trans.Commit(); } else { try { trans.Rollback(); } catch { } } } } } return(rs); }
public override async Task <int> HandleCommand(UpdateCommand request, CancellationToken cancellationToken) { if (request.Pesticide == null || request.Pesticide.Id == 0) { throw new BusinessException("Pesticide.NotExisted"); } var pesticide = await pesticideQueries.GetById(request.Pesticide.Id); if (pesticide == null) { throw new BusinessException("Pesticide.NotExisted"); } if ((request.Pesticide?.CategoryId ?? 0) > 0) { var category = await pesticideCategoryQueries.GetById(request.Pesticide.CategoryId ?? 0); if (category == null) { throw new BusinessException("Category.NotExisted"); } } var rs = -1; using (var conn = DALHelper.GetConnection()) { conn.Open(); using (var trans = conn.BeginTransaction()) { try { request.Pesticide.CreatedDate = pesticide.CreatedDate; request.Pesticide.CreatedBy = pesticide.CreatedBy; request.Pesticide = UpdateBuild(request.Pesticide, request.LoginSession); request.Pesticide.Code = string.IsNullOrWhiteSpace(pesticide.Code) ? (await storageQueries.GenarateCodeAsync(StorageKeys.PesticideCode)) : pesticide.Code; rs = await pesticideRepository.Update(request.Pesticide); if (rs == 0) { return(-1); } rs = 0; } catch (Exception ex) { throw ex; } finally { if (rs == 0) { trans.Commit(); } else { try { trans.Rollback(); } catch { } } } } } return(rs); }