Example #1
0
        public ActionResult ThanhToan()
        {
            var cart = (Cart)Session["CartSession"];
            var acc  = context.users.Find(idAccount);

            if (cart == null || cart.lines.Count() == 0 || acc == null)
            {
                return(RedirectToAction("Login", "User"));
            }
            else
            {
                foreach (var it in cart.lines)
                {
                    if (it.Product.Status_checking == "hotel")
                    {
                        DateTime checkin  = Convert.ToDateTime(it.Product.Checkin);
                        DateTime checkout = Convert.ToDateTime(it.Product.Checkout);
                        TimeSpan t        = checkout - checkin;

                        var ht_booking = new hotel_booking();
                        ht_booking.customer_address = acc.address;
                        ht_booking.customer_email   = acc.email;
                        ht_booking.customer_name    = acc.full_name;
                        ht_booking.customer_phone   = acc.phone;
                        ht_booking.user_id          = acc.id;

                        ht_booking.hotel_id    = int.Parse(it.Product.Id);
                        ht_booking.from_date   = checkin;
                        ht_booking.to_date     = checkout;
                        ht_booking.total_price = ((int)t.TotalDays * int.Parse(it.Product.Sell_price));

                        context.hotel_booking.Add(ht_booking);
                        context.SaveChanges();
                    }
                    else if (it.Product.Status_checking == "homestay")
                    {
                        DateTime checkin  = Convert.ToDateTime(it.Product.Checkin);
                        DateTime checkout = Convert.ToDateTime(it.Product.Checkout);
                        TimeSpan t        = checkout - checkin;

                        var hstay_booking = new homestay_booking();
                        hstay_booking.customer_address = acc.address;
                        hstay_booking.customer_email   = acc.email;
                        hstay_booking.customer_name    = acc.full_name;
                        hstay_booking.customer_phone   = acc.phone;
                        hstay_booking.user_id          = acc.id;

                        hstay_booking.homestay_id = int.Parse(it.Product.Id);
                        hstay_booking.from_date   = checkin;
                        hstay_booking.to_date     = checkout;
                        hstay_booking.total_price = ((int)t.TotalDays * int.Parse(it.Product.Sell_price));

                        context.homestay_booking.Add(hstay_booking);
                        context.SaveChanges();
                    }
                }
                cart.Clear();
                return(RedirectToAction("Index", "Home"));
            }
        }
Example #2
0
        public void EditUser_BE(int id_old, string json)
        {
            user acc = JsonConvert.DeserializeObject <user>(json);

            context.users.Add(acc);
            context.SaveChanges();
            var hotel_bookings = context.hotel_booking.Where(x => x.user_id == id_old).ToList();

            var homestay_bookings = context.homestay_booking.Where(x => x.user_id == id_old).ToList();


            foreach (var it in hotel_bookings)
            {
                hotel_booking htb = new hotel_booking(acc.id, acc.full_name, acc.email, acc.phone, acc.address, it.hotel_id, it.from_date, it.to_date, it.total_price, it.selectDichVu, it.thanhTienDichVu, "Đang xử lý");
                context.hotel_booking.Add(htb);
                context.SaveChanges();
                context.hotel_booking.Remove(it);
                context.SaveChanges();
            }
            foreach (var it in homestay_bookings)
            {
                homestay_booking hsb = new homestay_booking(acc.id, acc.full_name, acc.email, acc.phone, acc.address, it.homestay_id, it.from_date, it.to_date, it.total_price, it.selectDichVu, it.thanhTienDichVu, "Đang xử lý");
                context.homestay_booking.Add(hsb);
                context.SaveChanges();
                context.homestay_booking.Remove(it);
                context.SaveChanges();
            }
            context.users.Remove(context.users.Find(id_old));
            context.SaveChanges();
        }