Ejemplo n.º 1
0
        public async Task SavePost(Post post)
        {
            // upload extras
            if (post.Images.Any(m => string.IsNullOrEmpty(m.Id)))
            {
                foreach (var image in post.Images)
                {
                    var azureFileData = await AppMedia.UploadMedia(image.Url, "/api/Uploads/PostPhoto");

                    if (azureFileData == null)
                    {
                        throw new Exception("Error uploading file");
                    }

                    image.Url       = azureFileData.Url;
                    image.Blob      = azureFileData.BlobName;
                    image.Container = "posts";
                }
                await Post("/api/Posts", post);
            }
            else if (post.Videos.Any(m => string.IsNullOrEmpty(m.Id)))
            {
                Task.Run(async() =>
                {
                    foreach (var video in post.Videos)
                    {
                        var imageAzureFileData = await AppMedia.UploadMedia(video.ImageUrl, "/api/Uploads/PostPhoto");
                        if (imageAzureFileData == null)
                        {
                            throw new Exception("Error uploading image");
                        }

                        var azureFileData = await AppMedia.UploadMedia(video.Url, "/api/Uploads/PostPhoto");
                        if (azureFileData == null)
                        {
                            throw new Exception("Error uploading video");
                        }

                        video.Url            = azureFileData.Url;
                        video.Blob           = azureFileData.BlobName;
                        video.Container      = "posts";
                        video.ImageUrl       = imageAzureFileData.Url;
                        video.ImageBlob      = imageAzureFileData.BlobName;
                        video.ImageContainer = "posts";
                    }

                    await Post("/api/Posts", post);
                });
            }
            else
            {
                await Post("/api/Posts", post);
            }
        }
Ejemplo n.º 2
0
        public async Task <string> SaveUser(string filePath)
        {
            var user = CrossSettings.Current.GetValueOrDefaultJson <User>("User");

            if (!string.IsNullOrEmpty(filePath))
            {
                var azureFileData = await AppMedia.UploadMedia(filePath, "/api/Uploads/UserProfilePhoto");

                if (azureFileData == null)
                {
                    return("There was a problem while uploading the file");
                }

                user.ProfileUrl  = azureFileData.Url;
                user.ProfileBlob = azureFileData.BlobName;
            }

            // Save profile
            var result = await new ServiceApi().SaveUser(user);

            CrossSettings.Current.AddOrUpdateJson("User", result);

            return(null);
        }
Ejemplo n.º 3
0
        public async Task <string> SaveAthleteUser(string filePath, DateTime fromDate, DateTime?untilDate, string teamId)
        {
            AthleteUser athleteUser = new AthleteUser();

            athleteUser.User = CrossSettings.Current.GetValueOrDefaultJson <User>("User");
            if (!string.IsNullOrEmpty(filePath))
            {
                var azureFileData = await AppMedia.UploadMedia(filePath, "/api/Uploads/UserProfilePhoto");

                if (azureFileData == null)
                {
                    return("There was a problem while uploading the file");
                }
                athleteUser.User.ProfileUrl  = azureFileData.Url;
                athleteUser.User.ProfileBlob = azureFileData.BlobName;
            }

            athleteUser.Athlete          = new Athlete();
            athleteUser.Athlete.StartUtc = fromDate;
            athleteUser.Athlete.EndUtc   = untilDate;
            athleteUser.Athlete.TeamId   = teamId;

            // Save profile and athlete
            try
            {
                var result = await new ServiceApi().SaveAthleteUser(athleteUser);
                CrossSettings.Current.AddOrUpdateJson("User", result.User);
                CrossSettings.Current.AddOrUpdateJson("Athlete", result.Athlete);
            }
            catch (Exception e)
            {
                return(e.Message);
            }

            return(null);
        }