public override OrderModel Get(int id) { var order = cache.Get(ApplicationCacheConstants.GetOrderCacheKey(id)) as OrderModel; if (order != null) { return(order); } broker.SetupCommand(ORDER_GET); broker.AddInputParameter("@id", id); order = new OrderModel(); using (IDataReader rdr = broker.GetDataReader()) { while (rdr.Read()) { order.Id = rdr["id"].SafeToInt(); order.EmployeeId = rdr["empId"].SafeToInt(); order.NumberOfSeats = rdr["NumberOfSeats"].SafeToInt(); order.TableId = rdr["tableId"].SafeToInt(); order.Delivered = rdr["delivered"].SafeToBool(); order.Voided = false; order.InProgress = rdr["inProgress"].SafeToBool(); OrderItemRepository orderItemRepo = new OrderItemRepository(order.Id, cache); order.OrderItems = orderItemRepo.GetAll().ToList(); order.Ready = order.OrderItems.All(oi => oi.Ready != null && oi.Ready.Value); } } cache.Set(ApplicationCacheConstants.GetOrderCacheKey(id), order); return(order); }
public override MenuModel Get(int id) { string key = ApplicationCacheConstants.GetMenuItemCacheKey(id); MenuModel model = cache.Get(key) as MenuModel; if (model != null) { return(model); } broker.SetupCommand(MENU_GET); broker.AddInputParameter("@id", id); using (IDataReader rdr = broker.GetDataReader()) { if (rdr.Read()) { model = new MenuModel(); model.Id = id; model.Name = rdr["name"].SafeToString(); model.Description = rdr["description"].SafeToString(); model.MenuCategory = new MenuCategoryModel(); model.MenuCategory.Name = rdr["CategoryName"].SafeToString(); model.MenuCategory.Id = rdr["CategoryId"].SafeToInt(); model.Price = double.Parse(rdr["price"].SafeToString()); } } cache.Set(ApplicationCacheConstants.GetMenuItemCacheKey(model.Id), model); return(model); }
public override bool Delete(int id) { broker.SetupCommand(MENU_DELETE); broker.AddInputParameter("@id", id); bool deleted = broker.ExecuteNonQuery().SafeToInt() > 0; if (deleted) { cache.Remove(ApplicationCacheConstants.GetMenuItemCacheKey(id)); } return(deleted); }
public override bool Create(OrderModel model) { broker.SetupCommand(ORDER_INSERT); broker.AddInputParameter("@NumberofSeats", model.NumberOfSeats); broker.AddInputParameter("@EmployeeId", model.EmployeeId); broker.AddInputParameter("@TableId", model.TableId); model.Id = broker.ExecuteScalar().SafeToInt(); if (model.Id > 0) { cache.Set(ApplicationCacheConstants.GetOrderCacheKey(model.Id), model); } return(model.Id > 0); }
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); }
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 Update(MenuModel model) { broker.SetupCommand(MENU_UPDATE); broker.AddInputParameter("@price", model.Price); broker.AddInputParameter("@menucategoryid", model.MenuCategory.Id); broker.AddInputParameter("@name", model.Name); broker.AddInputParameter("@description", model.Description); broker.AddInputParameter("@id", model.Id); bool updated = broker.ExecuteNonQuery().SafeToInt() > 0; if (updated) { cache.Set(ApplicationCacheConstants.GetMenuItemCacheKey(model.Id), model); } return(updated); }
public override bool Create(MenuModel model) { broker.SetupCommand(MENU_CREATE); broker.AddInputParameter("@price", model.Price); broker.AddInputParameter("@menucategoryid", model.MenuCategory.Id); broker.AddInputParameter("@name", model.Name); broker.AddInputParameter("@description", model.Description); model.Id = broker.ExecuteScalar().SafeToInt(); bool inserted = model.Id > 0; if (inserted) { cache.Set(ApplicationCacheConstants.GetMenuItemCacheKey(model.Id), model); } return(inserted); }
public bool UpdateAndClose(OrderModel model, bool close = true) { broker.SetupCommand(ORDER_UPDATE); broker.AddInputParameter("@id", model.Id); broker.AddInputParameter("@NumberOfSeats", model.NumberOfSeats); broker.AddInputParameter("@delivered", model.Delivered, dbType: DbType.Boolean); broker.AddInputParameter("@inprogress", model.InProgress, dbType: DbType.Boolean); broker.AddInputParameter("@voided", model.Voided, dbType: DbType.Boolean); broker.AddInputParameter("@close", close); bool updated = broker.ExecuteNonQuery() > 0; if (updated) { cache.Set(ApplicationCacheConstants.GetOrderCacheKey(model.Id), model); } return(updated); }
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); }
private void ClearOrderCache(int orderId) { cache.Remove(ApplicationCacheConstants.GetOrderCacheKey(orderId)); }