public virtual async Task <IActionResult> GetById([FromRoute] int id) { try { var model = Service.ReadById(id); if (model == null) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.NOT_FOUND_STATUS_CODE, General.NOT_FOUND_MESSAGE) .Fail(); return(NotFound(Result)); } else { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.OK_STATUS_CODE, General.OK_MESSAGE) .Ok(model, Service.MapToViewModel); return(Ok(Result)); } } catch (Exception e) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message) .Fail(); return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, Result)); } }
public double CheckStockQuantity(int Id, int StockId) { var stock = StockService.ReadById(StockId); var stockQuantity = stock.Quantity; if (Id > 0) { var existingQuantity = DbSetItem.Where(i => i.ExpenditureId == Id && i.StockId == StockId).Select(s => s.Quantity).FirstOrDefault(); stockQuantity += existingQuantity; } return(stockQuantity); }