Ejemplo n.º 1
0
        public ActionResult Edit(ReportViewModel model)
        {
            if (model.RoomIds == null || model.RoomIds.Count <= 0 || model.CheckInDate == DateTime.MinValue || model.Price == null)
            {
                TempData["Message"] = "回報資訊不完整";
                if (model.ID != 0)
                {
                    return(RedirectToAction("Edit", new { id = model.ID }));
                }
                else
                {
                    return(RedirectToAction("Edit"));
                }
            }


            //model.HotelID = _dbzh.Room.Find(model.HotelID).Hotel.ID;
            var IsAdmin   = (User.IsInRole("Admin") || User.IsInRole("System"))? true:false;
            var IsMyHotel = _db.HotelZH.Any(o => o.ID == model.HotelID && o.UserId == CurrentUser.Id);

            if (!IsAdmin && !IsMyHotel)
            {
                return(View());
            }
            var Now    = DateTime.Now;
            var UserId = CurrentUser.Id;

            model.Created  = Now;
            model.Creator  = UserId;
            model.Modified = Now;
            model.Modify   = UserId;
            //model.CheckInDate = Now;


            //model.Room = _dbzh.Room.Find(model.RoomID).Name;
            try
            {
                if (model.ID <= 0)
                {
                    model.Create();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    model.UserName = User.Identity.Name;
                    model.Edit();
                    return(RedirectToAction("Edit", new { id = model.ID }));
                }
            }
            catch
            {
                var Hotel = _db.HotelZH.Where(o => o.UserId == CurrentUser.Id).FirstOrDefault();
                var Rooms = Hotel == null ? new List <RoomZH>() : Hotel.RoomZH;
                ViewBag.Rooms = new SelectList(Rooms, "ID", "Name");
                var Country = _db.Country.ToList();
                ViewBag.Country = new SelectList(Country, "ID", "Name");
                ModelState.AddModelError("", "編輯未完成,請檢查資料");
                return(View());
            }
        }
Ejemplo n.º 2
0
        //
        // GET: /Report/
        public ActionResult Index()
        {
            var viewModel = ReportViewModel.Create(Repository, Site);

            return(View(viewModel));
        }