public TableDto<GroupBuyStore> Get(int limit = 1000, int offset = 0, string search = null, string order = "asc", string category=null)
        {
            List<GroupBuyStore> stores;
            TableDto<GroupBuyStore> list;
            using (var db = new HoGameEISContext())
            {
                stores = db.GroupBuyStores.ToList();

                if (search != null)
                    stores = stores.Where(o => o.StoreName.Contains(search)).ToList();

                if (!String.IsNullOrEmpty(category))
                    stores = stores.Where(o => o.Category.Contains(category)).ToList();

                int total = stores.Count();

                stores = stores.Skip(offset).Take(limit).ToList();

                list = new TableDto<GroupBuyStore>()
                {
                    total = total,
                    rows = stores
                };
            }

            return list;
        }
        public TableDto<GroupBuyDto> GetGroupbuyList(int limit = 1000, int offset = 0, string search = null, string order = "asc", string category = null)
        {
            List<GroupBuyDto> groupbuys; ;
            TableDto<GroupBuyDto> list;
            using (var db = new HoGameEISContext())
            {
                var sql = @"[dbo].[usp_GetGroupbuyList] @isOngoing";
                groupbuys = db.Database.SqlQuery<GroupBuyDto>(sql, new SqlParameter("@isOngoing", category == "ongoing")).ToList();

                if (search != null)
                    groupbuys = groupbuys.Where(o => o.Description.Contains(search)).ToList();

                int total = groupbuys.Count();

                groupbuys = groupbuys.Skip(offset).Take(limit).ToList();

                list = new TableDto<GroupBuyDto>()
                {
                    total = total,
                    rows = groupbuys
                };
            }

            return list;
        }
        public List<GroupBuyItem> Get(int id,string action = "")
        {
            List<GroupBuyItem> order = new List<GroupBuyItem>();
            using (var db = new HoGameEISContext())
            {
                order = db.GroupBuyItems.Where(o => o.GroupBuyId == id).ToList();

                order.ForEach((m) =>
                {
                    m.SubItems = db.GroupBuySubItems.Where(s => s.ItemId == m.ItemId).ToList();
                    List<GroupBuySubItem> subItems = m.SubItems.ToList();
                    subItems.ForEach((si) =>
                    {
                        si.GroupBuySubscribers = db.GroupBuySubscribers.Where(gs => gs.SubItemId == si.SubItemId).ToList();
                    });
                });

                if (action == "orderDetail") {
                    //過濾未被選擇的子項目
                    order.ForEach((m) =>
                    {
                        m.SubItems = m.SubItems.Where(o => o.GroupBuySubscribers.Count > 0).ToList();
                    });
                }

            }
            return order;
        }
 public void Post([FromBody]GroupBuySubItem item)
 {
     using (var db = new HoGameEISContext())
     {
         db.GroupBuySubItems.Add(item);
         db.SaveChanges();
     }
 }
 public Boolean Delete(int id)
 {
     int result = 0;
     using (var db = new HoGameEISContext())
     {
         var sql = @"exec [dbo].[usp_DeleteGroupBuyMenuItem] @ItemId";
         result = db.Database.ExecuteSqlCommand(sql, new SqlParameter("@ItemId", id));
     }
     return result != 0;
 }
 public Boolean Post([FromBody]GroupBuyStoreItem item)
 {
     int result = 0;
     using (var db = new HoGameEISContext())
     {
         var sql = @"exec [dbo].[usp_AddGroupBuyMenuItem] @StoreId";
         result = db.Database.ExecuteSqlCommand(sql, new SqlParameter("@StoreId", item.StoreId));
     }
     return result != 0;
 }
 public void Put(int id, [FromBody]GroupBuyStoreItem item)
 {
     using (var db = new HoGameEISContext())
     {
         GroupBuyStoreItem _item =  db.GroupBuyStoreItems.Where(o => o.ItemId == id).FirstOrDefault();
         _item.ItemName = item.ItemName;
         db.Entry(_item).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
 }
 public void Post(GroupBuyPaid paid)
 {
     using (var db = new HoGameEISContext())
     {
         var sql = @"exec [dbo].[usp_SetGroupBuyPaid] @EmployeeId,@GroupBuyId,@Paid";
         db.Database.ExecuteSqlCommand(sql,
             new SqlParameter("@EmployeeId", paid.EmployeeId),
             new SqlParameter("@GroupBuyId", paid.GroupBuyId),
             new SqlParameter("@Paid", paid.Paid));
     }
 }
        public List<GroupBuyDto> Get()
        {
            List<GroupBuyDto> gb = new List<GroupBuyDto>();
            using (var db = new HoGameEISContext())
            {
                var sql = @"[dbo].[usp_GetGroupbuyList] @isCurrent";
                gb = db.Database.SqlQuery<GroupBuyDto>(sql, new SqlParameter("@isCurrent", false)).ToList();
            }

            return gb;
        }
示例#10
0
        public GroupBuyDto Get(int id)
        {
            GroupBuyDto gb;
            using (var db = new HoGameEISContext())
            {
                var sql = @"[dbo].[usp_GetGroupbuyDetail] @GroupBuyId, @EmployeeId";
                gb = db.Database.SqlQuery<GroupBuyDto>(sql,
                    new SqlParameter("@GroupBuyId", id),
                    new SqlParameter("@EmployeeId", CurrentUser.EmployeeId)).FirstOrDefault();
            }

            return gb;
        }
        public List<GroupBuyStoreItem> Get(int id)
        {
            List<GroupBuyStoreItem> menu = new List<GroupBuyStoreItem>();
            using (var db = new HoGameEISContext())
            {
                menu =  db.GroupBuyStoreItems.Where(o => o.StoreId == id).ToList();

                menu.ForEach(m => m.SubItems
                = db.GroupBuyStoreSubItems.Where(s => s.ItemId == m.ItemId).ToList());

            }
            return menu;
        }
        public GroupBuyStore Get(int id)
        {
            GroupBuyStore store = new GroupBuyStore()
            {
                StoreId = id
            };

            using (var db = new HoGameEISContext())
            {
                store = db.GroupBuyStores.Find(store.StoreId);
            }
            return store;
        }
示例#13
0
        public ActionResult Login(FormCollection formCollection, String ReturnUrl)
        {
            if (User.Identity.IsAuthenticated) {
                return RedirectToAction("Index", "Home");
            }

            String account = formCollection["InputEmail"];
            string password = formCollection["password"];

            if (account == null)
            {
                return View();
            }
            using (var db = new HoGameEISContext())
            {
                Boolean isRememberMe = formCollection["RememberMe"].Contains("true");
                Employee emp = db.Employees.Where(o => o.Email.Contains(account.Trim()) && (o.Password==null || o.Password == password)).FirstOrDefault();
                if (emp != null)
                {
                    System.Web.Script.Serialization.JavaScriptSerializer objSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                    string userData = objSerializer.Serialize(emp);

                    DateTime expires = DateTime.Now.AddMonths(1);

                    FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,
                      emp.FullName,//你想要存放在 User.Identy.Name 的值,通常是使用者帳號
                      DateTime.Now,
                      expires,
                      isRememberMe,//將管理者登入的 Cookie 設定成 Session Cookie
                      userData,
                      FormsAuthentication.FormsCookiePath);

                    string encTicket = FormsAuthentication.Encrypt(ticket);
                    HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
                    authCookie.Expires = expires;
                    Response.Cookies.Add(authCookie);

                    if (String.IsNullOrEmpty(ReturnUrl))
                    {
                        return RedirectToAction("Index", "Home");
                    }
                    else
                    {
                        return Redirect(ReturnUrl);
                    }

                }

            }
            return View();
        }
 public void Delete(int id)
 {
     using (var db = new HoGameEISContext())
     {
         GroupBuySubItem _subItem = db.GroupBuySubItems.Where(o => o.SubItemId == id).FirstOrDefault();
         db.Entry(_subItem).State = System.Data.Entity.EntityState.Deleted;
         List<GroupBuySubscriber> _subscribers = db.GroupBuySubscribers.Where(s => s.SubItemId==id).ToList();
         foreach (GroupBuySubscriber subscriber in _subscribers)
         {
             db.Entry(subscriber).State = System.Data.Entity.EntityState.Deleted;
         }
         db.SaveChanges();
     }
 }
示例#15
0
        public ActionResult CreateGroupBuy(FormCollection formData)
        {
            using (var db = new HoGameEISContext())
            {
                var sql = @"exec [dbo].[usp_AddGroupBuy] @Description=@Description,@EndTime=@EndTime,@StoreId=@StoreId,@Creator=@Creator";
                db.Database.ExecuteSqlCommand(sql,
                    new SqlParameter("@Description", formData["Description"]),
                    new SqlParameter("@EndTime", formData["EndTime"]),
                    new SqlParameter("@StoreId", Int32.Parse(formData["StoreId"])),
                    new SqlParameter("@Creator", CurrentUser().EmployeeId)
                    );
            }

            return RedirectToAction("CurrentGroupBuy", "GroupBuy");
        }
        public List<GroupBuyMenuImage> GetGroupbuyList(int id)
        {
            List<GroupBuyMenuImage> images;
            using (var db = new HoGameEISContext())
            {
                images = db.GroupBuyMenuImages.Where(o => o.GroupBuyId == id).ToList();
            }

            foreach (var img in images)
            {
                img.ImageUrl = String.Format("{0}{1}", ImageUploadUrl, img.ImageUrl);
            }

            return images;
        }
        public void Delete(int id)
        {
            using (var db = new HoGameEISContext())
            {
                List<GroupBuyStoreMenuImage> images = new List<GroupBuyStoreMenuImage>();
                images = db.GroupBuyStoreMenuImages.Where(o => o.StoreId == id).ToList();

                foreach (var img in images)
                {
                    GroupBuyImageApiController.deleteblobFile(img.ImageUrl);
                }

                var sql = @"exec [dbo].[usp_DeleteGroupBuyStore] @StoreId";
                db.Database.ExecuteSqlCommand(sql, new SqlParameter("@StoreId", id));
            }
        }
 public void Put(int id, [FromBody]GroupBuyStoreSubItem item)
 {
     if (String.IsNullOrEmpty(item.Action)) {
         return;
     }
     using (var db = new HoGameEISContext())
     {
         GroupBuyStoreSubItem _item = db.GroupBuyStoreSubItems.Where(o => o.SubItemId == id).FirstOrDefault();
         if (item.Action == "SubItemName") {
             _item.SubItemName = item.SubItemName;
         }
         if (item.Action == "Price")
         {
             _item.Price = item.Price;
         }
         db.Entry(_item).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
 }
        public List<GroupBuyPaidDetailDto> Get(int id)
        {
            List<GroupBuyPaidDetailDto> Details;
            using (var db = new HoGameEISContext())
            {
                var sql = @"[dbo].[usp_GetGroupbuyPaid] @GroupBuyId";
                Details = db.Database.SqlQuery<GroupBuyPaidDetailDto>(sql, new SqlParameter("@GroupBuyId", id)).ToList();

                Details.ForEach((d) => {
                    d.SubscriberItems = db.Database.SqlQuery<GroupBuySubscriberItemDto>(
                        @"[dbo].[usp_GetGroupbuySubscriber] @GroupBuyId,@EmployeeId",
                        new SqlParameter("@GroupBuyId", id),
                        new SqlParameter("@EmployeeId", d.EmployeeId))
                        .ToList();
                });

            }
            return Details;
        }
示例#20
0
        public ActionResult ChangePassword(FormCollection formCollection)
        {
            string password = formCollection["password"];

            Employee emp;
            using (var db = new HoGameEISContext())
            {
                int employeeId = CurrentUser().EmployeeId;
                emp = db.Employees.Where(o => o.EmployeeId == employeeId).FirstOrDefault<Employee>();

                if (emp != null)
                {
                    emp.Password = password;

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

                    db.SaveChanges();
                }

            }
            return RedirectToAction("Logout");
        }
        public async Task<List<GroupBuyStoreMenuImage>> Post(int id)
        {
            //var streamProvider = new MultipartFormDataStreamProvider(ServerUploadFolder);

            //await Request.Content.ReadAsMultipartAsync(streamProvider);



            var provider = new MultipartFileStreamProvider(Path.GetTempPath());

            // Read the form data.
            await Request.Content.ReadAsMultipartAsync(provider);
            foreach (MultipartFileData file in provider.FileData)
            {
                //string fileName = blobSaveFile(file);
                string fileName = localSaveFile(file);
                GroupBuyStoreMenuImage image = new GroupBuyStoreMenuImage()
                {
                    StoreId = id,
                    ImageUrl = fileName
                };

                using (var db = new HoGameEISContext())
                {
                    db.GroupBuyStoreMenuImages.Add(image);
                    db.SaveChanges();
                }
            }
            return Get(id);
        }
        public static void deleteLocalFile(string fileName)
        {
            try
            {
                using (var db = new HoGameEISContext())
                {
                    //檢查菜單圖片已存在團購,就不刪除實體圖片。
                    if (!db.GroupBuyMenuImages.ToList().Exists(o => o.ImageUrl == fileName))
                    {
                        string filepath = Path.Combine(ConfigurationManager.AppSettings["ImageLocalPath"], fileName);
                        if (File.Exists(filepath))
                            File.Delete(filepath);
                    }
                }


            }
            catch (Exception ex)
            {

            }
        } 
        public void Delete(int id)
        {
            GroupBuyStoreMenuImage image = new GroupBuyStoreMenuImage();
            using (var db = new HoGameEISContext())
            {
                image = db.GroupBuyStoreMenuImages.Where(o => o.ImageId == id).FirstOrDefault<GroupBuyStoreMenuImage>();

            }
            using (var db = new HoGameEISContext())
            {
                db.Entry(image).State = System.Data.Entity.EntityState.Deleted;
                db.SaveChanges();
            }

            deleteblobFile(image.ImageUrl);
        }
示例#24
0
        public void GroupbuyEndTime(int GroupBuyId, GroupBuy input)
        {
            GroupBuy groupBuy;

            using (var db = new HoGameEISContext())
            {
                groupBuy = db.GroupBuys.Where(o => o.GroupBuyId == GroupBuyId).FirstOrDefault<GroupBuy>();

                if (groupBuy != null)
                {
                    groupBuy.EndTime = input.EndTime;

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

                    db.SaveChanges();
                }

            }
        }
示例#25
0
        public GroupbuySecurityDto GroupbuySecurity(int GroupBuyId)
        {
            GroupbuySecurityDto securtiy = new GroupbuySecurityDto()
            {
                Role = ""
            };

            using (var db = new HoGameEISContext())
            {
                if (db.GroupBuys.Any(o => o.GroupBuyId == GroupBuyId && o.Creator == CurrentUser.EmployeeId))
                {
                    securtiy.Role += "GroupBuyCreator;";
                }

            }
            return securtiy;
        }
示例#26
0
 public void GroupbuyChangeStore(GroupBuy groupBuy)
 {
     using (var db = new HoGameEISContext())
     {
         var sql = @"exec [dbo].[usp_ChangeGroupBuyStore] @StoreId, @GroupBuyId";
         db.Database.ExecuteSqlCommand(sql,
             new SqlParameter("@StoreId", groupBuy.StoreId),
             new SqlParameter("@GroupBuyId", groupBuy.GroupBuyId));
     }
 }
示例#27
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");
        }