public IActionResult OnPostPublish(string Name, string Type, IFormFile image, string Description) { if (workRepository.GetBy("Name", Name) == null) { byte[] imageData = null; using (var binaryReader = new BinaryReader(image.OpenReadStream())) { imageData = binaryReader.ReadBytes((int)image.Length); } PeopleWork work = new PeopleWork() { Id = Guid.NewGuid(), User_Id = userRepository.GetBy("Username", HttpContext.Session.GetString("username")).Id, Name = Name, Description = Description, DateSent = DateTime.Now, Type = Type, Image = imageData }; workRepository.Insert(work); return(RedirectToPage("user_profile")); } else { NameValid = "This name is already used"; return(Page()); } }
public IActionResult OnGet() { if (HttpContext.Session.GetString("username") == null) { return(RedirectToPage("Index")); } if (HttpContext.Session.GetString("workname") == null) { return(RedirectToPage("CommunityWorks")); } else { PeopleWork work = workRepository.GetBy("Name", HttpContext.Session.GetString("workname")); User author = userRepository.GetBy("Id", work.User_Id.ToString()); var comments = commentRepository.GetAll(); SortedComments = comments.OrderBy(x => x.DateSent).ToList(); Image = work.Image; Name = work.Name; AuthorName = author.Username; AuthorAvatar = author.Avatar; Type = work.Type; Description = work.Description; DateSent = work.DateSent; Likes = work.Likes; return(Page()); } }
public void LeaveLike(string usernameLike, string workname) { User user = userRepository.GetBy("username", usernameLike); PeopleWork work = workRepository.GetBy("name", workname); Like oldLike = likeRepository.GetBy("Work_Id", work.Id.ToString(), "User_Id", user.Id.ToString()); if (oldLike == null) { Like like = new Like { Id = Guid.NewGuid(), User_Id = user.Id, Work_Id = work.Id, IsLiked = 1, NumberOfChange = 1, DateSent = DateTime.Now }; work.Likes++; workRepository.Update(work); likeRepository.Insert(like); } else { oldLike.NumberOfChange++; oldLike.DateSent = DateTime.Now; if (oldLike.NumberOfChange % 2 != 0) { oldLike.IsLiked = 1; work.Likes++; } else { work.Likes--; oldLike.IsLiked = 0; } workRepository.Update(work); likeRepository.Update(oldLike); } int likes = work.Likes; InvokeClientMethodToAllAsync("pingLike", likes); }