/// <summary>
 /// Convert TrainingPlan Entity  into TrainingPlan Object
 /// </summary>
 ///<param name="model">TrainingPlanViewModel</param>
 ///<param name="TrainingPlanEntity">DataAccess.TrainingPlan</param>
 ///<returns>TrainingPlanViewModel</returns>
 public static TrainingPlanViewModel ToViewModel(
     this DataAccess.TrainingPlan entity,
     TrainingPlanViewModel model)
 {
     model.Id                = entity.Id;
     model.EventId           = entity.EventId;
     model.FinYearId         = entity.FinYearId;
     model.Name              = entity.Name;
     model.Objective         = entity.Objective;
     model.FinYear           = entity.FinYear.Name;
     model.Event             = entity.Event.Name;
     model.MemberIds         = entity.TrainingPlanMembers.Select(a => a.MemberId).ToArray();
     model.DistanceIds       = entity.TrainingPlanDistances.Select(a => a.DistanceId).ToArray();
     model.RaceDefinitionIds = entity.TrainingPlanRaceDefinitions.Select(a => a.RaceDefinitionId).ToArray();
     return(model);
 }
 /// <summary>
 /// Convert TrainingPlan Object into TrainingPlan Entity
 /// </summary>
 ///<param name="model">TrainingPlan</param>
 ///<param name="TrainingPlanEntity">DataAccess.TrainingPlan</param>
 ///<returns>DataAccess.TrainingPlan</returns>
 public static DataAccess.TrainingPlan ToEntity(this TrainingPlanViewModel model,
                                                DataAccess.TrainingPlan entity)
 {
     if (entity.Id == 0)
     {
         entity.CreatedUserId = model.SessionUserId;
         entity.IsActive      = model.IsActive;
     }
     else
     {
         entity.UpdatedUserId    = model.SessionUserId;
         entity.UpdatedTimestamp = DateTime.Now;
     }
     entity.Name      = model.Name;
     entity.Objective = model.Objective;
     entity.FinYearId = model.FinYearId;
     entity.EventId   = model.EventId;
     return(entity);
 }
        public static TrainingPlanQLViewModel ToQueryViewModel(
            this DataAccess.TrainingPlan entity,
            TrainingPlanQLViewModel model)
        {
            model.Id                = entity.Id;
            model.EventId           = entity.EventId;
            model.FinYearId         = entity.FinYearId;
            model.Name              = entity.Name;
            model.EventName         = entity.Event.Name;
            model.Objective         = entity.Objective;
            model.DistanceCount     = entity.TrainingPlanDistances.Count();
            model.MemberCount       = entity.TrainingPlanMembers.Count();
            model.FinYear           = entity.FinYear.Name;
            model.Event             = entity.Event.ToViewModel(new EventViewModel());
            model.MemberIds         = entity.TrainingPlanMembers.Select(a => a.MemberId).ToArray();
            model.DistanceIds       = entity.TrainingPlanDistances.Select(a => a.DistanceId).ToArray();
            model.RaceDefinitionIds = entity.TrainingPlanRaceDefinitions.Select(a => a.RaceDefinitionId).ToArray();
            model.RaceDefinitions   = entity.TrainingPlanRaceDefinitions.Select(a => a.RaceDefinition.Name);
            model.Distances         = entity.TrainingPlanDistances.Select(a => a.Distance.Name);

            model.Members = entity.TrainingPlanMembers.Select(a => a.Member).AsQueryable().ToQueryListViewModel();
            return(model);
        }