Exemplo n.º 1
0
        public ActionResult Edit(int?id)
        {
            var seat   = seatService.GetByID(id);
            var seatVM = new NewSeatViewModel();

            return(View("SeatForm", Mapper.Map(seat, seatVM)));
        }
Exemplo n.º 2
0
        public ActionResult Save(NewSeatViewModel SeatVM)
        {
            var R_Id = Request.Cookies["idCookie"].Values["r_id"];

            if (!ModelState.IsValid)
            {
                TempData["seatMessage"] = "bootbox.alert('請輸入桌號!');";
                return(View("Index", SeatVM));
            }
            //New
            if (SeatVM.Id == 0 || SeatVM.Id == null)
            {
                var instance = Mapper.Map <NewSeatViewModel, Seat>(SeatVM);
                instance.R_Id = R_Id;
                var result = seatService.Create(instance);
                var times  = reservationService.GetSettingList(R_Id);
                if (times.Count() != 0)
                {
                    var seatId = instance.Id;
                    foreach (var time in times)
                    {
                        var time_instance = new SetReservationDetails()
                        {
                            R_id            = R_Id,
                            ReservationTime = time.ReservationTime,
                            SeatId          = seatId
                        };
                        reservationService.CreateTime(time_instance);
                    }
                }

                string msg = result.Success == true ?  "" : "bootbox.alert('錯誤,請重新再試一次!');";
                TempData["seatMessage"] = msg;
                return(RedirectToAction("Index"));
            }
            else
            {
                var SeatInDb = seatService.GetByID(SeatVM.Id);
                Mapper.Map(SeatVM, SeatInDb);
                SeatInDb.R_Id = R_Id;
                var    result = seatService.Update(SeatInDb);
                string msg    = result.Success == true ? "bootbox.alert('修改成功', function(){ location.replace('/Seat/Index'); });" : "bootbox.alert('錯誤,請重新再試一次!');";
                TempData["seatEditMessage"] = msg;
                return(View("Index"));
            }
        }