/// <summary> /// Does basic completness/sanity checks on location dto. Throws an /// InvalidDTOException when any validation check fails. This method must /// be used in a try/catch block! /// </summary> /// <param name="locationDTO"></param> public static void ValidateLocationDTO(DTOLocation locationDTO) { if (locationDTO == null) { throw new InvalidDTOException("Invalid location informaiton supplied (null reference)"); } }
// --------------------------------------------------------------------- /// <summary> /// Builds a DTO with tables and session, but EXLUDES reservations, /// this is because; /// 1 - A location has reference to a reservation, and a reservation /// has reference to a locaiton so we could easily build a never-ending nested /// DTO. /// 2 - A location may have a LARGE amount of reservations! So only get selected ones. /// /// Also excludes any background image data; get this in a seperate call. /// /// </summary> /// <param name="location"></param> /// <returns></returns> public static DTOLocation BuildLocationDTO(Location location) { DTOLocation locationDto = null; if (location != null) { locationDto = new DTOLocation(); locationDto.Id = location.Id; locationDto.Name = location.Name; locationDto.DefaultDuration = location.DefaultDuration; locationDto.Width = location.PlanWidth; locationDto.Height = location.PlanHeight; IList <DTOSession> dtoSessions = new List <DTOSession>(); foreach (Session s in location.Sessions) { dtoSessions.Add(BuildSessionDTO(s)); } locationDto.Sessions = dtoSessions.ToArray <DTOSession>(); IList <DTOReservable> dtoReservables = new List <DTOReservable>(); foreach (Table r in location.Tables) { dtoReservables.Add(BuildReservableDTO(r, null)); } locationDto.ReservableList = dtoReservables.ToArray <DTOReservable>(); } return(locationDto); }
// TODO: check other dto/business objects for sensible hashcode/equals implementations public override bool Equals(object obj) { DTOLocation other = obj as DTOLocation; if (other == null) { return(false); } return(this.Id == other.Id); }
// --------------------------------------------------------------------- /// <summary> /// /// </summary> /// <param name="r"></param> /// <returns></returns> public static DTOReservable BuildReservableDTO(Table r, Terminal t) { DTOReservable reservableDTO = new DTOReservable(); if (r != null) { reservableDTO.Id = r.Id; reservableDTO.Name = r.Name; reservableDTO.MaxGuests = r.MaxGuests; // create a 'shallow' dto location DTOLocation pl = new DTOLocation(); pl.Id = r.ParentLocation.Id; pl.Name = r.ParentLocation.Name; reservableDTO.ParentLocation = pl; // send back the current interest level if (r.Id != 0) { reservableDTO.CurrentInterestLevel = ReservationsService.GetTableInterestLevel(r.Id); } // table plan data reservableDTO.X = r.X; reservableDTO.Y = r.Y; reservableDTO.Width = r.Width; reservableDTO.Height = r.Height; reservableDTO.RotationAngle = r.RotationAngle; reservableDTO.Shape = r.Shape; reservableDTO.TableColor = r.Status(t); reservableDTO.Number = r.Number; } return(reservableDTO); }