Example #1
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 }));
        }
Example #2
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));
        }
        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)));
        }
Example #4
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));
        }