Exemplo n.º 1
0
        public ActionResult StoreManagementEdit(int id =-1)
        {
            GroupBuyStore store = new GroupBuyStore()
            {
                Category = "meal"
            };

            if (id != -1)
            {
                store = new GroupBuyStoreApiController().Get(id);
            }
            return View("App");
        }
        public GroupBuyStore Get(int id)
        {
            GroupBuyStore store = new GroupBuyStore()
            {
                StoreId = id
            };

            using (var db = new HoGameEISContext())
            {
                store = db.GroupBuyStores.Find(store.StoreId);
            }
            return store;
        }
Exemplo n.º 3
0
        public ActionResult StoreManagementEdit(FormCollection formData, int id = -1)
        {
            GroupBuyStore groupBuyStore;

            if (id != -1)
            {
                using (var db = new HoGameEISContext())
                {
                    groupBuyStore = db.GroupBuyStores.Where(o => o.StoreId == id).FirstOrDefault<GroupBuyStore>();

                    if (groupBuyStore != null)
                    {
                        groupBuyStore.StoreName = formData["StoreName"];
                        groupBuyStore.Address = formData["Address"];
                        groupBuyStore.Tel = formData["Tel"];
                        groupBuyStore.Category = formData["Category"];
                        groupBuyStore.Memo = formData["Memo"];

                        db.Entry(groupBuyStore).State = System.Data.Entity.EntityState.Modified;

                        //4. call SaveChanges
                        db.SaveChanges();
                    }

                }
            }
            else
            {
                using (var db = new HoGameEISContext())
                {
                    groupBuyStore = new GroupBuyStore()
                    {
                        StoreName = formData["StoreName"],
                        Address = formData["Address"],
                        Tel = formData["Tel"],
                        Category = formData["Category"],
                        Memo = formData["Memo"]
                    };
                    db.GroupBuyStores.Add(groupBuyStore);
                    db.SaveChanges();
                }
            }
            return RedirectToAction("StoreManagement", "GroupBuy");
        }