예제 #1
0
        public FrontComment(Comment comment, Account authorAccount, bool showReport = false)
        {
            this.ShowReport = showReport;
            Id = comment.Id;
            IsMember = true;
            ClubRequestBool = false;
            Time = comment.Time;
            Text = comment.Text;
            NumDroplets = comment.NumDroplets;
            ClubId = comment.ClubId;
            Picture = comment.Picture;
            UserEmoji = authorAccount.Emoji;
            AuthorAccountColor = authorAccount.Color;
            TextColor = "black";

            if (comment.AuthorId == App.dbWrapper.GetUser().Id)
            {
                AuthorUsername = "******";
                TextColor = AuthorAccountColor;
            }
            else
            {
                AuthorUsername = authorAccount.Username;
            }


        }
예제 #2
0
        //NOTE: in the server, the access info is that of the storage account, not the mobile service
        //and it operates on a key value pair, 

        /// Create an DBImage class and send it to the server
        public async Task<string> CreateDBImage(string path, string clubId)
        {
            DBImage DBImage = new DBImage();

            //set properties of the DBImage
            DBImage.ContainerName = "containerName";
            DBImage.ResourceName = Guid.NewGuid().ToString();

            //upload DBImage, the server will give it an sasquerystring
            await DBImageTable.InsertAsync(DBImage);

            //if the server assigned the string
            if (!string.IsNullOrEmpty(DBImage.SasQueryString))
            {
                System.Diagnostics.Debug.WriteLine("SAS STRING WAS MADE ----------------------");
                StorageCredentials credentials = new StorageCredentials(DBImage.SasQueryString);
                var DBImageUri = new Uri(DBImage.DBImageUri);
                System.Diagnostics.Debug.WriteLine("-----------------URI---------------"+DBImageUri.ToString());

                //instatiate blob container given credentials
                CloudBlobContainer container = new CloudBlobContainer(
                    new Uri(string.Format("https://{0}/{1}", DBImageUri.Host, DBImage.ContainerName)), credentials
                    );

                //files are unmanaged resources so they should be used like this
                //a managed resource is one that is handled by the garbage collector
                using (var inputStream = File.OpenRead(path))
                {
                    //upload the DBImage from the file stream
                    CloudBlockBlob blob = container.GetBlockBlobReference(DBImage.ResourceName);
                    await blob.UploadFromStreamAsync(inputStream);
                    System.Diagnostics.Debug.WriteLine("IT ACTUALLY WORKED!!!!!!!!!!!!!!!!!! NO WAY!!!!!!!!------------------");
                }

                //add a comment that references the picture for easy retrieval in clubs: the DBImage's id is stored in the text field
                //NOTE: assumes the user is a member of the club as a precondition
                Club club = await clubTable.LookupAsync(clubId);

                Comment comment = new Comment(User.Id, clubId, DBImage.Id);
                comment.Picture = true;
                await commentTable.InsertAsync(comment);

                //update user
                User.NumComments++;
                await accountTable.UpdateAsync(User);

            }
            else
            {
                System.Diagnostics.Debug.WriteLine("SAS STRING NOT MADE-------------------------------");
            }

            return path;
        }
예제 #3
0
        ///Create a comment; returns 1 if success, 2 if not a member of the club, 3 if banned
        /// NOTE: calling thigs with push notifications before finished registering, ERROR
        public async Task<int> CreateComment(string text, string clubId)
        {
            //check if banned (must get current instance of user account incase ban happend since login)
            User = await accountTable.LookupAsync(User.Id);
            if(DateTime.Compare(User.Banned,DateTime.Now)>0){
                return 3;
            }
            System.Diagnostics.Debug.WriteLine("mydebug---"+User.Id);

            Club club = await clubTable.LookupAsync(clubId);

            System.Diagnostics.Debug.WriteLine("mydebug----"+club.Id);

            //check if user is in club
            var list = await memberJuncTable.Where(item => item.AccountId == User.Id && item.ClubId == club.Id).ToListAsync();

            if (list.Count > 0)
            {
                Comment comment = new Comment(User.Id, clubId, text);
                await commentTable.InsertAsync(comment);

                //update user
                User.NumComments++;
                await accountTable.UpdateAsync(User);

                System.Diagnostics.Debug.WriteLine("mydebug----" + "finished");

                return 1;
            }
            else
            {
                return 2;
            }

        }