public override OrderItemModel Get(int id) { var model = cache.Get(ApplicationCacheConstants.GetOrderItemCacheKey(id)) as OrderItemModel; if (model != null) { return(model); } broker.SetupCommand(ORDER_GET); broker.AddInputParameter("@id", id); model = broker.GetObject <OrderItemModel>().First(); cache.Set(ApplicationCacheConstants.GetOrderItemCacheKey(id), model); return(model); }
public override bool Delete(int id) { broker.SetupCommand(ORDER_DELETE); broker.AddInputParameter("@id", id); bool deleted = broker.ExecuteNonQuery().SafeToInt() > 0; var cachedItem = cache.Get(ApplicationCacheConstants.GetOrderItemCacheKey(id)) as OrderItemModel; if (deleted && cachedItem != null) { ClearOrderCache(cachedItem.OrderId); cache.Remove(ApplicationCacheConstants.GetOrderItemCacheKey(id)); } return(deleted); }
private bool Create(OrderItemModel model, bool clearOrderCache) { broker.SetupCommand(ORDER_INSERT); broker.AddInputParameter("@comment", model.Comment); broker.AddInputParameter("@seatNumber", model.SeatNumber); broker.AddInputParameter("@menuId", model.MenuId); broker.AddInputParameter("@orderId", model.OrderId); model.Id = broker.ExecuteScalar().SafeToInt(); if (model.Id > 0) { cache.Set(ApplicationCacheConstants.GetOrderItemCacheKey(model.Id), model); } if (clearOrderCache) { ClearOrderCache(model.Id); } return(model.Id > 0); }
private bool Update(OrderItemModel model, bool clearOrderCache) { broker.SetupCommand(ORDER_UPDATE); broker.AddInputParameter("@id", model.Id); broker.AddInputParameter("@comment", model.Comment); broker.AddInputParameter("@seatNumber", model.SeatNumber); broker.AddInputParameter("@menuId", model.MenuId); if (model.Ready.HasValue) { broker.AddInputParameter("@ready", model.Ready.Value, dbType: System.Data.DbType.Boolean); } bool updated = broker.ExecuteNonQuery() > 0; if (updated) { cache.Set(ApplicationCacheConstants.GetOrderItemCacheKey(model.Id), model); } if (clearOrderCache) { ClearOrderCache(model.Id); } return(updated); }