/// <summary> /// Populate seance data /// Create entity if none given /// </summary> /// <param name="dto"></param> /// <param name="entity"></param> /// <returns></returns> public static Seance Populate(SeanceDto dto, Seance entity = null) { if (entity == null) { entity = new Seance(); } entity.Date = dto.Date ?? default(DateTime); entity.Price = dto.Price; return(entity); }
/// <summary> /// Extract event entity into event Dto /// </summary> /// <param name="entity"></param> /// <returns></returns> public static EventDto Extract(Event entity) { var dto = new EventDto(); if (entity == null) { return(dto); } dto.Id = entity.Id; dto.Name = entity.Name; dto.Date = entity.Date; dto.IsPublished = entity.IsPublished; dto.Description = entity.Description; dto.Resume = entity.Resume; dto.NumberMaxOfParticipant = entity.NbMaxOfParticipant; dto.RendezVousPoint = entity.RendezVousPoint; if (entity.Participants != null) { dto.NumberOfParticipant = entity.Participants.Count; } if (entity.Creator != null) { dto.CreatorName = entity.Creator.UserName; } // Get participants if (entity.Participants != null && entity.Participants.Any()) { dto.Participants = entity.Participants.Select(pr => UserDto.Extract(pr.User)).ToList(); } // Get hosts if (entity.Hosts != null && entity.Hosts.Any()) { dto.Hosts = entity.Hosts.Select(hs => UserDto.Extract(hs.User)).ToList(); } //dto.Seance = SeanceDto.Extract(entity.Seances); if (entity.Seances != null && entity.Seances.Any()) { dto.Seance = entity.Seances.Select(sc => SeanceDto.Extract(sc.Seance)).ToList(); } return(dto); }
/// <summary> /// Extract data /// </summary> /// <param name="entity"></param> /// <returns></returns> public static SeanceDto Extract(Seance entity) { var dto = new SeanceDto(); if (entity == null) { return(dto); } dto.Id = entity.Id; dto.Date = entity.Date; dto.Price = entity.Price; if (entity.Movie != null) { dto.Movie = MovieDto.Extract(entity.Movie); } return(dto); }
// public static List<SeanceDto> Extract(List<Seance> entities) // { // return entities.Select(SeanceDto.Extract).ToList(); // } /// <summary> /// Extract data /// </summary> /// <param name="entities"></param> /// <returns></returns> public static List <SeanceDto> Extract(IEnumerable <SeanceEvent> entities) { return(entities.Select(se => SeanceDto.Extract(se.Seance)).ToList()); }
public static Event Populate(EventDto dto, Event entity = null, User creator = null) { // create new event if none exists if (entity == null) { entity = new Event(); } // Populate data if (!string.IsNullOrEmpty(dto.Name)) { entity.Name = dto.Name; } if (dto.Date != default(DateTime)) { entity.Date = dto.Date; } if (!string.IsNullOrEmpty(dto.Description)) { entity.Description = dto.Description; } if (dto.NumberMaxOfParticipant != default(int)) { entity.NbMaxOfParticipant = dto.NumberMaxOfParticipant; } if (!string.IsNullOrEmpty(dto.Resume)) { entity.Resume = dto.Resume; } if (!string.IsNullOrEmpty(dto.RendezVousPoint)) { entity.RendezVousPoint = dto.RendezVousPoint; } entity.IsPublished = dto.IsPublished; if (creator != null && entity.Creator == null) { entity.Creator = creator; } if (dto.Seance != null && dto.Seance.Any()) { foreach (var seanceDto in dto.Seance) { var tmp = entity.Seances.FirstOrDefault(se => se.SeanceId == seanceDto.Id); if (tmp != null) { tmp.Seance = SeanceDto.Populate(seanceDto, tmp.Seance); } else { tmp = new SeanceEvent() { EventId = dto.Id, Seance = SeanceDto.Populate(seanceDto) }; } } } return(entity); }