コード例 #1
0
        //將房間加到我的最愛
        public string AddRoomToFavorite(int RoomID)
        {
            var roomName = db.Room.Where(r => r.ID == RoomID).FirstOrDefault().RoomName;
            var roomfa   = db.RoomFavorite.Where(r => r.MemberID == tMember.fMemberId && r.RoomID == RoomID);

            if (roomfa.Count() == 0)
            {
                try
                {
                    RoomFavorite roomfv = new RoomFavorite()
                    {
                        MemberID = tMember.fMemberId, RoomID = RoomID
                    };
                    db.RoomFavorite.Add(roomfv);
                    db.SaveChanges();

                    //50010 加入我的最愛
                    CInformationFactory x = new CInformationFactory();
                    x.Add(tMember.fMemberId, 400, 0, 40010);

                    return($"已成功將 {roomName} 加入我的最愛");
                }
                catch (Exception)
                {
                    return($"出現錯誤!請稍後再嘗試!");
                }
            }
            else
            {
                return("我的最愛裡已有此房間");
            }
        }
コード例 #2
0
        public string DeleteAnOrder(int id)
        {
            Order od = db.Order.FirstOrDefault(p => p.OrderID == id);

            var odd = db.OrderDetails.Where(q => q.OrderID == id);

            if (od != null)
            {
                if (od.OrderDate.AddDays(7) < DateTime.Now)
                {
                    return("此筆訂單已超過七天鑑賞期,無法退貨囉!");
                }
                if (odd.Count() != 0)
                {
                    foreach (var ITEM in odd)
                    {
                        db.OrderDetails.Remove(ITEM);
                    }
                }
                db.Order.Remove(od);
                CInformationFactory x = new CInformationFactory();
                x.Add(tMember.fMemberId, 100, id, 30020);
                db.SaveChanges();
                return("您的訂單已取消~");
            }
            return("發生錯誤,請稍後再試!");
        }
コード例 #3
0
        public string MakeOrder(List <CAddtoSessionView> cart)
        {
            Order order      = new Order();
            int   totalPrice = 0;

            if (cart != null && cart.Count() != 0)
            {
                foreach (var item in cart)
                {
                    try
                    {
                        OrderDetails orderDetail = new OrderDetails();
                        orderDetail.ProductID = item.txtProductID;
                        orderDetail.Quantity  = item.txtQuantity;
                        //同步修改庫存
                        db.Product.Where(r => r.ProductID == item.txtProductID).FirstOrDefault().Stock -= item.txtQuantity;
                        db.Product.Where(r => r.ProductID == item.txtProductID).FirstOrDefault().Sales += item.txtQuantity;
                        orderDetail.ProductName = db.Product.Where(r => r.ProductID == item.txtProductID).FirstOrDefault().ProductName;
                        orderDetail.UnitPrice   = db.Product.Where(r => r.ProductID == item.txtProductID).FirstOrDefault().UnitPrice;
                        totalPrice += item.txtQuantity * orderDetail.UnitPrice;
                        order.OrderDetails.Add(orderDetail);
                    }
                    catch (Exception)
                    {
                        return("發生錯誤,請稍後再試!");
                    }
                }
            }
            order.OrderDate = DateTime.Now;

            order.TotalAmount   = totalPrice;
            order.OrderStatusID = 1;
            order.SendingStatus = "等待付款中";
            order.PayStatus     = "尚未付款";
            order.MemberID      = this.tMember.fMemberId;
            try
            {
                db.Order.Add(order);
                db.SaveChanges();
                CInformationFactory x = new CInformationFactory();
                x.Add(tMember.fMemberId, 100, order.OrderID, 30010);
            }
            catch (Exception)
            {
                return("發生錯誤,請稍後再試!");
            }
            return($"{order.OrderID}");
        }