Пример #1
0
        public async Task<ActionResult> Create(RoomViewModel roomView)
        {
            if (ModelState.IsValid)
            {
                var room = roomRep.Create(new Room
                {
                    HotelId = roomView.HotelId,
                    Name = roomView.Name,
                    StandartPrice = roomView.StandartPrice,
                    Price = roomView.Price,
                    Quantity = roomView.Quantity,
                    Status = 1
                });

                await uow.SaveAsync();
                return RedirectToAction("Index");
            }

            ModelState.AddModelError("", "操作失败。");
            var hotels = await hotelRep.Get(h => h.Status == 1).ToListAsync();
            ViewData["SelectHotel"] = new SelectList(hotels, "Id", "Name");
            return View(roomView);
        }
Пример #2
0
        public async Task<ActionResult> Edit(RoomViewModel model)
        {
            if (ModelState.IsValid)
            {
                var entity = roomRep.FindById(model.Id);
                if (entity == null)
                {
                    return HttpNotFound();
                }

                entity.HotelId = model.HotelId;
                entity.Name = model.Name;
                entity.StandartPrice = model.StandartPrice;
                entity.Price = model.Price;
                entity.Quantity = model.Quantity;
                roomRep.Update(entity);

                await uow.SaveAsync();
                return RedirectToAction("Index");
            }
            ModelState.AddModelError("", "操作失败。");
            var hotels = await hotelRep.Get(h => h.Status == 1).ToListAsync();
            ViewData["SelectHotel"] = new SelectList(hotels, "Id", "Name", model.HotelId);
            return View(model);
        }