Пример #1
0
        public async Task<ActionResult> Index(int page = 1)
        {
            var entities = await roomOrderRep.Get().OrderByDescending(r => r.BookingDate).ToListAsync();

            var models = new List<RoomOrderViewModel>();

            RoomOrderViewModel model;

            foreach (var o in entities)
            {
                model = new RoomOrderViewModel();
                model.OrderId = o.OrderId;
                model.UserId = o.UserId;
                model.UserName = o.UserId > 0 ? (await UserManager.FindByIdAsync(o.UserId)).UserName : "";
                model.FullName = o.FullName;
                model.PhoneNumber = o.PhoneNumber;
                model.Email = o.Email;
                var room = roomRep.FindById(o.RoomId);
                model.RoomName = room.Name;
                model.HotelName = hotelRep.FindById(room.HotelId).Name;
                model.Quantity = o.Quantity;
                model.BookingDate = o.BookingDate;
                model.CheckInDate = o.CheckInDate;
                model.CheckOutDate = o.CheckOutDate;
                if (o.OrderStatus == 0 && DateTime.Now >= o.CheckOutDate)
                {
                    model.OrderStatus = OrderStatus.已过期;
                }
                else
                {
                    model.OrderStatus = (OrderStatus)o.OrderStatus;
                }
                model.PaymentStatus = (PaymentStatus)o.PaymentStatus;
                model.Amount = o.Amount;
                model.Paid = o.Paid;

                models.Add(model);
            }

            return View(models.ToPagedList(page, 10));
        }
Пример #2
0
        public async Task<ActionResult> Create(RoomOrderViewModel model)
        {
            if (ModelState.IsValid)
            {
                Random random = new Random();
                string strRan = random.Next(0, 999).ToString();
                switch (strRan.Length)
                {
                    case 1: strRan = "00" + strRan; break;
                    case 2: strRan = "0" + strRan; break;
                }
                string orderId = "1" + DateTime.Now.ToString("yyMMddHHmmss") + strRan;

                var room = roomRep.FindById(model.RoomId);

                var entity = roomOrderRep.Create(new RoomOrder
                {
                    OrderId = orderId,
                    UserId = 0,
                    FullName = model.FullName,
                    PhoneNumber = model.PhoneNumber,
                    Email = model.Email,
                    Remark = model.Remark,
                    RoomId = model.RoomId,
                    Quantity = model.Quantity,
                    BookingDate = DateTime.Now,
                    CheckInDate = model.CheckInDate.AddHours(12),
                    CheckOutDate = model.CheckOutDate.AddHours(12),
                    Amount = room.StandartPrice * model.Quantity * (model.CheckOutDate - model.CheckInDate).Days,
                    Paid = 0.00M,
                    OrderStatus = 0,
                    PaymentStatus = 0
                });

                await uow.SaveAsync();
                return RedirectToAction("Index");
            }
            ModelState.AddModelError("", "操作失败。");

            var hotels = await hotelRep.Get(h => h.Status == 1).OrderBy(h => h.Id).ToListAsync();
            ViewData["HotelSelectList"] = new SelectList(hotels, "Id", "Name", hotels.FirstOrDefault().Id);

            int hId = hotels.FirstOrDefault().Id;
            var rooms = await roomRep.Get(r => r.HotelId == hId && r.Status == 1).ToListAsync();
            ViewData["RoomSelectList"] = new SelectList(rooms, "Id", "Name");

            return View(model);
        }