protected void grd_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int    rowIndex = Convert.ToInt32(e.CommandArgument.ToString());
            string id       = this.grd.DataKeys[rowIndex]["ID"].ToString();

            if (e.CommandName == "updates")
            {
                DataTableConversion lsttodt = new DataTableConversion();
                var       lst = iSeatService.GetByID(Convert.ToInt32(id));
                DataTable dt  = lsttodt.ToDataTable(lst);
                if (dt != null && dt.Rows.Count > 0)
                {
                    HiddenField1.Value = dt.Rows[0]["ID"].ToString();
                    SeatNumber.Text    = dt.Rows[0]["SeatNumber"].ToString();
                    SeatSide.Text      = dt.Rows[0]["SeatSide"].ToString();
                    Submit.Text        = "Update";
                }
                else
                {
                    Submit.Text = "Save";
                }
            }
            else
            {
                DataTable dt     = new DataTable();
                bool      result = iSeatService.Delete(Convert.ToInt32(id));
                if (result)
                {
                    bindGrid();
                }
            }
        }
Esempio 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"));
            }
        }