Beispiel #1
0
        public JsonResult InsertProduct(IFormCollection data, IFormFile photo)
        {
            Byte   caId    = (byte)int.Parse(data["id"]);
            string imgPath = null;

            if (data["id"] != "" & data["name"] != "" & data["des"] != "" & photo != null)
            {
                string photoName = Guid.NewGuid().ToString() + ".jpg";
                using (var photopath = new FileStream(
                           iv_host.WebRootPath + @"\images\ProductImages\" + photoName,
                           FileMode.Create))
                {
                    photo.CopyTo(photopath);
                }
                imgPath = "/images/ProductImages/" + photoName;
                Product product = new Product();
                product.CategoryId         = caId;
                product.ProductName        = data["name"];
                product.ProductDescription = data["des"];
                product.ProductImagePath   = imgPath;
                _context.Add(product);
                _context.SaveChanges();
                return(Json(new { result = true, msg = "上傳成功" }));
            }
            else
            {
                return(Json(new { result = false, msg = "上傳失敗" }));
            }
        }
Beispiel #2
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 }));
        }
Beispiel #3
0
        public IActionResult Join(OrderBuyRecord r)
        {
            //未登入只能搜尋團購,不能使用(加入),若按下加入後會跳轉登入頁
            if (HttpContext.Session.GetInt32(cUtility.Current_User_Id) == null)
            {
                return(RedirectToAction("Login", "Member", new { from = "Buy/Index" }));
            }
            //若外送地址未填寫(null),則填入空字串
            r.MemberId = HttpContext.Session.GetInt32(cUtility.Current_User_Id).Value;
            if (r.ComeAddress == null)
            {
                r.ComeAddress = "";
            }
            //todo need server side validation
            //取得被加入的團購物件,可購買數量 - 被購買數量
            //加入購買紀錄物件,將修改寫入資料庫
            var order = db.Orders.Where(o => o.OrderId == r.OrderId).First();

            order.AvailableCount -= r.Count;
            db.Add(r);
            db.SaveChanges();
            //if server side validation is not passed, return view with user's filter option
            //if successed, redirect to history
            //傳到新加入團購的聊天室頁面
            return(RedirectToAction("Index", "ChatMessageRecords", new { grouptype = 1, groupid = r.OrderId }));
        }
Beispiel #4
0
        public async Task <IActionResult> Index(Order order)
        {
            //若未登入則跳轉登入頁
            if (HttpContext.Session.GetInt32(cUtility.Current_User_Id) == null)
            {
                return(RedirectToAction("Login", "Member"));
            }
            //填入 order 裡未從前端取得的值
            order.HostMemberId = HttpContext.Session.GetInt32(cUtility.Current_User_Id).Value;
            order.StartTime    = DateTime.Now;
            DistrictRef dist = db.DistrictRefs.Where(d => d.DistrictId == order.DistrictId)
                               .Include(d => d.City).First();
            string address = dist.City.CityName + dist.DistrictName + order.Address;
            //todo read this
            //https://stackoverflow.com/questions/30419739/return-to-view-with-async-await
            var latlong = cUtility.addressToLatlong(address);

            order.Latitude       = latlong[0];
            order.Longitude      = latlong[1];
            order.AvailableCount = order.MaxCount;
            order.IsActive       = true;
            if (order.OrderDescription == null)
            {
                order.OrderDescription = "";
            }
            //將 order 寫入資料庫
            db.Add(order);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index", "ChatMessageRecords", new { grouptype = 1, groupid = order.OrderId }));
        }
        public async Task <string> Create(string message, int orderid, int memberid, byte grouptype)
        {
            var memberphoto = _context.Members.Where(n => n.MemberId == memberid).Select(n => n.ProfileImagePath).FirstOrDefault();
            ChatMessageRecord chatMessageRecord = new ChatMessageRecord
            {
                GroupType    = grouptype,
                GroupId      = orderid,
                SentTime     = DateTime.Now,
                SentMemberId = memberid,
                Message      = message
            };

            _context.Add(chatMessageRecord);
            await _context.SaveChangesAsync();

            return(JsonConvert.SerializeObject(new Tuple <DateTime, string>(chatMessageRecord.SentTime, memberphoto)));
        }
Beispiel #6
0
 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("您已成功移除:");
     }
 }
Beispiel #7
0
        public async Task <IActionResult> Index(GarbageServiceOffersViewModel g)
        {
            if (HttpContext.Session.GetInt32(cUtility.Current_User_Id) == null)
            {
                return(RedirectToAction("Login", "Member"));
            }
            g.HostMemberId = HttpContext.Session.GetInt32(cUtility.Current_User_Id).Value;
            if (g.Address != null)
            {
                g.StartTime     = DateTime.Now;
                g.ServiceTypeId = 1;
                //get latlong from address
                DistrictRef dist = _context.DistrictRefs.Where(d => d.DistrictId == g.DistrictId)
                                   .Include(d => d.City).First();
                string address = dist.City.CityName + dist.DistrictName + g.Address;
                var    latlong = cUtility.addressToLatlong(address);
                g.Latitude          = latlong[0];
                g.Longitude         = latlong[1];
                g.IsActive          = true;
                g.gso.L3available   = g.L3maxCount;
                g.gso.L5available   = g.L5maxCount;
                g.gso.L14available  = g.L14maxCount;
                g.gso.L25available  = g.L25maxCount;
                g.gso.L33available  = g.L33maxCount;
                g.gso.L75available  = g.L75maxCount;
                g.gso.L120available = g.L120maxCount;
                _context.Add(g.gso);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "ChatMessageRecords", new { grouptype = 2, groupid = g.gso.GarbageServiceId }));
            }
            ViewData["DistrictId"]    = new SelectList(_context.DistrictRefs, "DistrictId", "DistrictName", g.DistrictId);
            ViewData["GoRangeId"]     = new SelectList(_context.RangeRefs, "RangeId", "RangeInMeaters", g.GoRangeId);
            ViewData["CityId"]        = new SelectList(_context.CityRefs, "CityId", "CityName", g.District);
            ViewData["ServiceTypeId"] = new SelectList(_context.ServiceTypeRefs, "ServiceTypeId", "ServiceName", g.ServiceTypeId);
            return(View(g));
        }
Beispiel #8
0
        //寫入通知
        public async Task <string> CreateNotification(int groupType, int orderId, int senderId, string notifyContent)
        {
            int        contentID                 = 0;
            DateTime   nowTime                   = DateTime.Now;
            List <int> targetMemberId            = new List <int>();
            List <Tuple <int, bool> > returnList = new List <Tuple <int, bool> >();

            //排除空訊息
            if (notifyContent != "")
            {
                NotifyContent n = new NotifyContent();
                n.ContentText = notifyContent;
                _context.Add(n);
                await _context.SaveChangesAsync();

                contentID = n.ContentId;
            }
            if (contentID != 0)
            {
                switch (groupType)
                {
                case 1:
                    var orderhost = await _context.Orders.Where(n => n.OrderId == orderId).Select(n => n.HostMemberId).ToListAsync();

                    var orderjoin = await _context.OrderBuyRecords.Where(n => n.OrderId == orderId).Select(n => n.MemberId).ToListAsync();

                    targetMemberId = orderhost.Union(orderjoin).ToList();
                    break;

                case 2:
                    var garbhost = await _context.GarbageServiceOffers.Where(n => n.GarbageServiceId == orderId).Select(n => n.HostMemberId).ToListAsync();

                    var garbjoin = await _context.GarbageServiceUseRecords.Where(n => n.GarbageServiceOfferId == orderId).Select(n => n.MemberId).ToListAsync();

                    targetMemberId = garbhost.Union(garbjoin).ToList();
                    break;

                case 3:
                    break;
                }
                targetMemberId.Remove(senderId);

                var existNotify         = _context.Notifications.Where(n => n.SourceType == groupType && n.SourceId == orderId);
                var existNotifyMemberId = existNotify.Where(n => n.Checked == false).Select(n => n.MemberId).Distinct().ToList();
                var x = targetMemberId.Except(existNotifyMemberId).ToList();
                foreach (int id in x)
                {
                    Notification notification = new Notification
                    {
                        MemberId   = id,
                        ContentId  = contentID,
                        SourceType = (byte)groupType,
                        SourceId   = orderId,
                        SentTime   = nowTime,
                        Checked    = false
                    };
                    _context.Add(notification);
                    returnList.Add(new Tuple <int, bool>(id, true));
                }
                var y = targetMemberId.Intersect(existNotifyMemberId).ToList();
                foreach (int id in y)
                {
                    var item = existNotify.Where(n => n.MemberId == id && n.Checked == false).FirstOrDefault();
                    item.SentTime  = nowTime;
                    item.ContentId = contentID;
                    //_context.Update(item);
                    returnList.Add(new Tuple <int, bool>(id, false));
                }
                await _context.SaveChangesAsync();
            }

            return(JsonConvert.SerializeObject(returnList));
        }