Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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);
        }