예제 #1
0
        public async Task <JsonResult> OnPostReplyAsync(int PawId, string PawMessage)
        {
            var returnMessage = "failure";
            var userName      = User.Identity.Name;
            var userId        = _userManager.GetUserId(User);

            if (!string.IsNullOrEmpty(userId))
            {
                UserPawDBO userPaw = new UserPawDBO();
                userPaw.UserId      = userId;
                userPaw.ParentPawId = PawId;
                userPaw.ChildPawId  = 0;
                userPaw.CreatedDate = DateTime.Now;
                userPaw.Message     = PawMessage;

                _context.UserPaws.Add(userPaw);
                await _context.SaveChangesAsync();

                returnMessage = "success";
            }
            else
            {
                returnMessage = "please login";
            }

            return(new JsonResult(returnMessage));
        }
예제 #2
0
        public async Task <IActionResult> OnPostAcceptMeuoweAsync(int?MeuoweId)
        {
            string userId = _userManager.GetUserId(User);

            if (null != MeuoweId)
            {
                UserMeuoweDBO userMeuowe = await(from meuowe in _context.UserMeuowes
                                                 where meuowe.Id.Equals(MeuoweId)
                                                 select meuowe).FirstOrDefaultAsync();

                if (null != userMeuowe)
                {
                    string meuoweUserId = await(from user in _context.ApplicationUsers
                                                where user.Id.Equals(userMeuowe.UserId)
                                                select user.Id
                                                ).FirstOrDefaultAsync();

                    UserPawDBO userPaw = await(from paw in _context.UserPaws
                                               where paw.Id.Equals(userMeuowe.PawId)
                                               select paw).FirstOrDefaultAsync();

                    userPaw.UserId = meuoweUserId;
                    await _context.SaveChangesAsync();

                    _context.UserMeuowes.Remove(userMeuowe);
                    await _context.SaveChangesAsync();
                }
            }
            return(new RedirectToPageResult("/Paws/UserPawHome", new { area = "Social" }));
        }
예제 #3
0
        // Partial Views
        /****************************************************************/
        public async Task <IActionResult> OnGetPawViewComponent(int pawId)
        {
            UserPawDBO userPaw = await(from paw in _context.UserPaws
                                       where paw.Id.Equals(pawId)
                                       select paw
                                       ).FirstOrDefaultAsync();

            return(ViewComponent("DisplayedPaw", new { userPaw = userPaw }));
        }
예제 #4
0
        public IActionResult OnPostDelete(int pawID)
        {
            var returnMessage = "failure";
            var userId        = _userManager.GetUserId(User);

            if (!string.IsNullOrEmpty(userId))
            {
                UserPawDBO userPaw = (from p in _context.UserPaws
                                      where p.Id.Equals(pawID) && p.UserId.Equals(userId)
                                      select p).FirstOrDefault();

                if (null != userPaw)
                {
                    _context.Remove(userPaw);
                    _context.SaveChangesAsync();
                    returnMessage = "success";
                }
            }

            return(new JsonResult(returnMessage));
        }
예제 #5
0
        private async Task <PawVM> GetItemsAsync(UserPawDBO userPaw)
        {
            string userId = _userManager.GetUserId(HttpContext.User);

            PawVM pawVM = new PawVM();

            var user = await(from usr in _context.ApplicationUsers
                             where usr.Id.Equals(userPaw.UserId)
                             select usr).FirstOrDefaultAsync();


            var userShake = await(from us in _context.UserShakes
                                  where us.UserId.Equals(userId) &&
                                  us.PawId.Equals(userPaw.Id)
                                  select us).FirstOrDefaultAsync();


            var userWagTail = await(from uw in _context.UserWags
                                    where uw.UserId.Equals(userId) &&
                                    uw.PawId.Equals(userPaw.Id)
                                    select uw).FirstOrDefaultAsync();


            int userShakeCount = await _context.UserShakes.
                                 Where(x => x.PawId.Equals(userPaw.Id)).CountAsync();

            int userWagCount = await _context.UserWags.
                               Where(x => x.PawId.Equals(userPaw.Id)).CountAsync();

            if (null != userId && userId.Equals(user.Id))
            {
                pawVM.Relation = 0;
            }
            else
            {
                pawVM.Relation = 1;
            }

            if (null != userShake)
            {
                pawVM.UserShake = userShake;
            }

            if (null != userWagTail)
            {
                pawVM.UserWagTail = userWagTail;
            }

            // 2. Connect to Azure Storage account.
            var connectionString = _configuration.GetConnectionString("AccessKey");
            BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);

            // 3. Use container for users profile photos.
            string containerName = "profilephotos";
            BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(containerName);

            // 4. Create new blob and upload to azure storage account.
            BlobClient blobClient = containerClient.GetBlobClient("profile-" + user.Id + ".png");

            if (!blobClient.Exists())
            {
                blobClient = containerClient.GetBlobClient("profiledefault.png");
            }

            //BlobDownloadInfo download = await blobClient.DownloadAsync();

            byte[] result = null;
            using (var ms = new MemoryStream())
            {
                blobClient.DownloadTo(ms);
                result = ms.ToArray();
            }


            string base64String = Convert.ToBase64String(result);

            string image = String.Format("data:image/png;base64,{0}", base64String);

            pawVM.UserPaw        = userPaw;
            pawVM.UserName       = user.UserName;
            pawVM.DisplayName    = user.DisplayName;
            pawVM.UserShakeCount = userShakeCount;
            pawVM.UserWagCount   = userWagCount;
            pawVM.AzurePhoto     = image;

            return(pawVM);
        }
예제 #6
0
        public async Task <IViewComponentResult> InvokeAsync(UserPawDBO userPaw)
        {
            PawVM pawVM = await GetItemsAsync(userPaw);

            return(View(pawVM));
        }