コード例 #1
0
        public IActionResult Join(GarbageServiceUseRecord r)
        {
            ////未登入只能搜尋服務,不能使用(加入),若按下加入會跳轉登入頁
            if (HttpContext.Session.GetInt32(cUtility.Current_User_Id) == null)
            {
                return(RedirectToAction("Login", "Member", new { from = "ServiceUse/Index" }));
            }
            //填入使用者id到使用紀錄
            r.MemberId = HttpContext.Session.GetInt32(cUtility.Current_User_Id).Value;
            //取得被使用服務
            var offer = db.GarbageServiceOffers.Where(o => o.GarbageServiceId == r.GarbageServiceOfferId).First();

            //some testing here need to be done
            //將被使用服務的可用袋數減去被使用袋數
            offer.L3available   -= r.L3count;
            offer.L5available   -= r.L5count;
            offer.L14available  -= r.L14count;
            offer.L25available  -= r.L25count;
            offer.L33available  -= r.L33count;
            offer.L75available  -= r.L75count;
            offer.L120available -= r.L120count;
            //加入使用紀錄,將修改寫入資料庫
            db.Add(r);
            db.SaveChanges();
            //傳到新加入服務團的聊天室頁面
            return(RedirectToAction("Index", "ChatMessageRecords", new { grouptype = 2, groupid = r.GarbageServiceOfferId }));
        }
コード例 #2
0
ファイル: BuyController.cs プロジェクト: sz55/LeSheTuanGo-1
        public void editOrderOffer(int OrderId, Order order)
        {
            //取得被修改資料"修改前"的可購買數和購買上限
            var o = db.Orders.Where(n => n.OrderId == OrderId).Select(n => new { n.AvailableCount, n.MaxCount }).First();

            //計算團購修改後新的可購買數
            order.AvailableCount = (byte)(o.AvailableCount + (order.MaxCount - o.MaxCount));
            //取得新地址的經緯度
            decimal[] s = cUtility.addressToLatlong(order.Address);
            order.Latitude  = s[0];
            order.Longitude = s[1];
            //寫入資料庫
            db.Update(order);
            db.SaveChanges();
            //Console.WriteLine("A");
        }
コード例 #3
0
ファイル: MapController.cs プロジェクト: sz55/LeSheTuanGo-1
 public string AdjFavorite(int mem, int spot, byte type)
 {
     if (type == 0) //+spot
     {
         var AdjSpot = new GarbageSpotLike {
             MemberId = mem, GarbageTruckSpotId = spot, MinutesBeforeNotify = 0, NotifyMe = false
         };
         iv_context.Add(AdjSpot);
         iv_context.SaveChanges();
         return("您已成功新增:");
     }
     else //-spot; type=1
     {
         var AdjSpot = iv_context.GarbageSpotLikes.Where(s => s.MemberId == mem && s.GarbageTruckSpotId == spot).First();
         iv_context.Remove(AdjSpot);
         iv_context.SaveChanges();
         return("您已成功移除:");
     }
 }
コード例 #4
0
        public string InsertCategory(string s)
        {
            var 商品類型重複 = _context.CategoryRefs.Where(n => n.CategoryName == s).ToList();

            if (商品類型重複.Count != 0)
            {
                return("商品類型重複");
            }
            else
            {
                CategoryRef category = new CategoryRef();
                category.CategoryName = s;
                _context.CategoryRefs.Add(category);
                _context.SaveChanges();
                var 商品選項 = _context.CategoryRefs.Select(n => new { n.CategoryId, n.CategoryName }).ToList();
                var 拉是選單 = JsonConvert.SerializeObject(商品選項);
                return(拉是選單);
            }
        }
コード例 #5
0
        //清除通知(已讀)
        public void ClearNotification(int senderId)
        {
            var notifylist = _context.Notifications.Where(n => n.MemberId == senderId && n.Checked == false).ToList();

            foreach (var item in notifylist)
            {
                item.Checked = true;
                _context.Update(item);
            }
            _context.SaveChanges();
        }
コード例 #6
0
 public IActionResult Create(MemberViewModel memberData)
 {
     if (string.IsNullOrEmpty(memberData.Address) || memberData.DistrictId == 0 || string.IsNullOrEmpty(memberData.Email) || string.IsNullOrEmpty(memberData.Password))
     {
         return(RedirectToAction("Create"));
     }
     #region 密碼加密
     RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
     byte[] buff = new byte[10];
     rng.GetBytes(buff);
     string salt = Convert.ToBase64String(buff);
     memberData.PasswordSalt = salt;
     memberData.Password     = sha256(memberData.Password, salt);
     #endregion
     #region 照片
     if (memberData.image != null)
     {
         string photoName = Guid.NewGuid().ToString() + ".jpg";
         using (var photo = new FileStream(
                    iv_host.WebRootPath + @"\images\ProfileImages\" + photoName,
                    FileMode.Create))
         {
             memberData.image.CopyTo(photo);
         }
         memberData.ProfileImagePath = "/images/ProfileImages/" + photoName;
     }
     else
     {
         string imageDefalt = "guestProfile.jpg";
         memberData.ProfileImagePath = "/images/ProfileImages/" + imageDefalt;
     }
     #endregion
     #region 地址轉經緯
     decimal[] addressToLatlong = new decimal[2];
     var       qDistrict        = db.DistrictRefs.Where(n => n.DistrictId == memberData.DistrictId).FirstOrDefault();
     var       qCity            = db.CityRefs.Where(n => n.CityId == qDistrict.CityId).FirstOrDefault();
     addressToLatlong     = cUtility.addressToLatlong(qCity.CityName + qDistrict.DistrictName + memberData.Address);
     memberData.Latitude  = addressToLatlong[0];
     memberData.Longitude = addressToLatlong[1];
     #endregion
     db.Members.Add(memberData.member);
     db.SaveChanges();
     sendEmail(memberData.Email, memberData.MemberId, "openMember");
     return(RedirectToAction("Login"));
 }
コード例 #7
0
        //編輯開團內容
        public void EditGarbageOffer(int garbageServiceID, GarbageServiceOffer garbageServiceOffer)
        {
            var g = _context.GarbageServiceOffers.Where(n => n.GarbageServiceId == garbageServiceID).Select(n => new
            {
                n.L3available,
                n.L3maxCount,
                n.L5available,
                n.L5maxCount,
                n.L14available,
                n.L14maxCount,
                n.L25available,
                n.L25maxCount,
                n.L33available,
                n.L33maxCount,
                n.L75available,
                n.L75maxCount,
                n.L120available,
                n.L120maxCount,
            }).ToList();

            if (garbageServiceID == garbageServiceOffer.GarbageServiceId)
            {
                decimal[] s = cUtility.addressToLatlong(garbageServiceOffer.Address);
                garbageServiceOffer.Latitude      = s[0];
                garbageServiceOffer.Longitude     = s[1];
                garbageServiceOffer.L3available   = (byte)(g[0].L3available + (garbageServiceOffer.L3maxCount - g[0].L3maxCount));
                garbageServiceOffer.L5available   = (byte)(g[0].L5available + (garbageServiceOffer.L5maxCount - g[0].L5maxCount));
                garbageServiceOffer.L14available  = (byte)(g[0].L14available + (garbageServiceOffer.L14maxCount - g[0].L14maxCount));
                garbageServiceOffer.L25available  = (byte)(g[0].L25available + (garbageServiceOffer.L25maxCount - g[0].L25maxCount));
                garbageServiceOffer.L33available  = (byte)(g[0].L33available + (garbageServiceOffer.L33maxCount - g[0].L33maxCount));
                garbageServiceOffer.L75available  = (byte)(g[0].L75available + (garbageServiceOffer.L75maxCount - g[0].L75maxCount));
                garbageServiceOffer.L120available = (byte)(g[0].L120available + (garbageServiceOffer.L120maxCount - g[0].L120maxCount));
                _context.Update(garbageServiceOffer);
                _context.SaveChanges();
            }
        }