public IResult DelSetTimes(SetReservationDetails instance) { if (instance == null) { throw new ArgumentNullException(); } bool oldValidateOnSaveEnabled = db.Configuration.ValidateOnSaveEnabled; IResult result = new Result(false); try { db.SetReservationDetails.Attach(instance); setReservartionRep.Delete(instance); result.Success = true; } catch (Exception e) { result.Exception = e; } finally { db.Configuration.ValidateOnSaveEnabled = oldValidateOnSaveEnabled; } return(result); }
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")); } }
public IResult CreateTime(SetReservationDetails instance) { if (instance == null) { throw new ArgumentNullException(); } IResult result = new Result(false); try { setReservartionRep.Create(instance); result.Success = true; } catch (Exception e) { result.Exception = e; } return(result); }