public ActionResult LayoutMap(int idlayout) { if (idlayout <= 0) { return(HttpNotFound()); } List <SeatDto> objsseats = _seatService.GetAllSeat(); List <AreaDto> objsareas = _areaService.GetAllArea().Where(a => a.TMLayoutId == idlayout).ToList(); List <AreaViewModel> areaViewModel = new List <AreaViewModel>(); List <SeatViewModel> localSeatsView = new List <SeatViewModel>(); List <SeatDto> localSeats; foreach (var item in objsareas) { localSeats = objsseats.Where(s => s.AreaId == item.Id).ToList(); foreach (var itemchild in localSeats) { localSeatsView.Add(new SeatViewModel { Number = itemchild.Number, Row = itemchild.Row, }); } areaViewModel.Add(new AreaViewModel { CoordX = item.CoordX, CoordY = item.CoordY, CountSeatsX = localSeats.Max(s => s.Number), CountSeatsY = localSeats.Max(s => s.Row), Description = item.Description, Seats = localSeatsView, }); } TMLayoutViewModel layoutViewModel = new TMLayoutViewModel { Layout = _tmlayoutService.GetTMLayout(idlayout), Areas = areaViewModel, }; return(PartialView("_LayoutMap", layoutViewModel)); }
public void RemoveLayout(int layoutId) { // for transaction List <AreaDto> areas = _areaService.GetAllArea() .Where(a => a.TMLayoutId == layoutId).ToList(); List <SeatDto> seats = _seatService.GetAllSeat() .Where(s => areas.Any(a => a.Id == s.AreaId)).ToList(); seats.ForEach(s => _seatService.RemoveSeat(s.Id)); areas.ForEach(a => _areaService.RemoveArea(a.Id)); try { _tmlayoutService.RemoveTMLayout(layoutId); } catch (System.Data.SqlClient.SqlException) { areas.ForEach(a => _areaService.CreateArea(a)); seats.ForEach(s => _seatService.CreateSeat(s)); } }