Exemple #1
0
        public async Task UpdateActivity(long athleteId, long activityId, string activityTitle, string activityType, bool?isPrivate)
        {
            var activityInDb = await this.db.Activities.FirstOrDefaultAsync(p => p.Id == activityId && p.AthleteId == athleteId);

            if (activityInDb == null)
            {
                return;
            }

            if (!string.IsNullOrEmpty(activityTitle))
            {
                activityInDb.Name = activityTitle;
            }

            if (!string.IsNullOrEmpty(activityType))
            {
                var activityTypeId = EnumsHelper.GetEnumIdByName <ActivityTypeEnum>(activityType);
                activityInDb.ActivityTypeId = activityTypeId;
            }

            if (isPrivate.HasValue)
            {
                activityInDb.IsPrivate = isPrivate.Value;
            }

            await this.db.SaveChangesAsync();
        }
        public StravaModelMappingsProfile()
        {
            this.CreateMap <SummaryActivity, Activity>()
            .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id.Value))
            .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name))
            .ForMember(dest => dest.ActivityTypeId, opt => opt.MapFrom(src => EnumsHelper.GetEnumIdByName <ActivityTypeEnum>(src.Type)))
            .ForMember(dest => dest.StartDate, opt => opt.MapFrom(src => DateTime.SpecifyKind(src.StartDate.Value, DateTimeKind.Utc)))
            .ForMember(dest => dest.EndDate, opt => opt.MapFrom(src => DateTime.SpecifyKind(src.StartDate.Value, DateTimeKind.Utc).AddSeconds(src.ElapsedTime.Value)))
            .ForMember(dest => dest.Duration, opt => opt.MapFrom(src => src.MovingTime ?? 0))
            .ForMember(dest => dest.Distance, opt => opt.MapFrom(src => (int)Math.Round(src.Distance ?? 0)))
            .ForMember(dest => dest.Elevation, opt => opt.MapFrom(src => (int)Math.Round(src.TotalElevationGain ?? 0)))
            .ForMember(dest => dest.Pace, opt => opt.MapFrom(src => src.AverageSpeed ?? 0))
            .ForMember(dest => dest.IsManual, opt => opt.MapFrom(src => src.Manual))
            .ForMember(dest => dest.IsGps, opt => opt.MapFrom(src => src.Map != null && !string.IsNullOrEmpty(src.Map.SummaryPolyline)))
            .ForMember(dest => dest.IsPrivate, opt => opt.MapFrom(src => src._Private ?? false))
            .ForMember(dest => dest.Athlete, opt => opt.Ignore());

            this.CreateMap <DetailedActivity, Activity>()
            .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id.Value))
            .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name))
            .ForMember(dest => dest.ActivityTypeId, opt => opt.MapFrom(src => EnumsHelper.GetEnumIdByName <ActivityTypeEnum>(src.Type)))
            .ForMember(dest => dest.StartDate, opt => opt.MapFrom(src => DateTime.SpecifyKind(src.StartDate.Value, DateTimeKind.Utc)))
            .ForMember(dest => dest.EndDate, opt => opt.MapFrom(src => DateTime.SpecifyKind(src.StartDate.Value, DateTimeKind.Utc).AddSeconds(src.ElapsedTime.Value)))
            .ForMember(dest => dest.Duration, opt => opt.MapFrom(src => src.MovingTime ?? 0))
            .ForMember(dest => dest.Distance, opt => opt.MapFrom(src => (int)Math.Round(src.Distance ?? 0)))
            .ForMember(dest => dest.Elevation, opt => opt.MapFrom(src => (int)Math.Round(src.TotalElevationGain ?? 0)))
            .ForMember(dest => dest.Pace, opt => opt.MapFrom(src => src.AverageSpeed ?? 0))
            .ForMember(dest => dest.IsManual, opt => opt.MapFrom(src => src.Manual))
            .ForMember(dest => dest.IsGps, opt => opt.MapFrom(src => src.Map != null && !string.IsNullOrEmpty(src.Map.SummaryPolyline)))
            .ForMember(dest => dest.IsPrivate, opt => opt.MapFrom(src => src._Private ?? false))
            .ForMember(dest => dest.Athlete, opt => opt.Ignore());

            this.CreateMap <SummaryClub, Club>()
            .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id.Value))
            .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name))
            .ForMember(dest => dest.SportType, opt => opt.MapFrom(src => CultureInfo.CurrentCulture.TextInfo.ToTitleCase(src.SportType)))
            .ForMember(dest => dest.IconUrl, opt => opt.MapFrom(src => src.ProfileMedium))
            .ForMember(dest => dest.Url, opt => opt.MapFrom(src => src.Url))
            .ForMember(dest => dest.MembersCount, opt => opt.MapFrom(src => src.MemberCount ?? 0));
        }