public UserDto FromUserToUserDto(User user) { UserDto userDto = new UserDto() { Id = user.Id, Login = user.Login, FirstName = user.FirstName, SecondName = user.SecondName, MiddleName = user.MiddleName, Rating = user.Rating, Birthday = user.BirthDate, RegistrationDate = user.RegistrationDate }; DateTime now = DateTime.Now; int age = now.Year - userDto.Birthday.Year; userDto.Age = age; foreach (Wall wall in user.Walls) { WallDto wallDto = FromWallToWallDto(wall); userDto.Walls.Add(wallDto); } userDto.ScoredPosts = FindScoredPosts(user); return(userDto); }
public WallDto GetWallDto(int wallId) { Wall wall = pageManager.GetWall(wallId); WallDto wallDto = mapper.FromWallToWallDto(wall); return(wallDto); }
public UserDto FromUserToUserDto(User user) { UserDto userDto = new UserDto() { Id = user.Id, Login = user.Login, FirstName = user.FirstName, SecondName = user.SecondName, MiddleName = user.MiddleName, Rating = user.Rating, Birthday = user.BirthDate, RegistrationDate = user.RegistrationDate, Banned = user.Banned, RoleId = user.SystemRoleId }; DateTime now = DateTime.Now; int age = now.Year - userDto.Birthday.Year; userDto.Age = age; foreach (Wall wall in user.Walls) { WallDto wallDto = FromWallToWallDto(wall); userDto.Walls.Add(wallDto); } userDto.Friends = GetFriendsInDto(user.Friendships); userDto.SentFriendshipRequests = GetFriendshipsRequestsDto(user.SentRequests.ToList()); userDto.ReceivedFriendshipRequests = GetFriendshipsRequestsDto(user.ReceivedRequests.ToList()); userDto.ScoredPosts = FindScoredPosts(user); return(userDto); }
public static WallDto GetWallDto(Wall wall) { var dto = new WallDto() { Id = wall.WallId, StartVertex = new Vertex(wall.StartVertexX, wall.StartVertexY), EndVertex = new Vertex(wall.EndVertexX, wall.EndVertexY) }; return(dto); }
public void UpdateWallMessage(int id, string message) { // init db Db db = new Db(); // update wall WallDto wall = db.Wall.Find(id); wall.Message = message; wall.DateEdited = DateTime.Now; db.SaveChanges(); }
public async Task Wall_GetWall_Should_Return_View_Model() { var wallId = 1; var wall = new WallDto { Id = wallId }; _wallService.WallDetails(0, null).ReturnsForAnyArgs(Task.Run(() => wall)); var response = await _wallController.GetWall(wallId); Assert.IsInstanceOf <OkNegotiatedContentResult <WallListViewModel> >(response); }
public WallDto FromWallToWallDto(Wall wall) { WallDto wallDto = new WallDto(); wallDto.Id = wall.Id; wallDto.WallType = wall.WallType.Title; foreach (Post post in wall.Posts) { PostDto postDto = FromPostToPostDto(post); wallDto.Posts.Add(postDto); } return(wallDto); }
public ActionResult Wall(int wallId) { WallDto wallDto = pageService.GetWallDto(wallId); return(PartialView(wallDto)); }
public WallViewModel(WallDto dto) { Id = dto.Id; Message = dto.Message; DateEdited = dto.DateEdited; }
//Very bad how i'm not injecting the main thread dispatcher... but this is a prototype and I'm running out of time. public static UcWall GetUcWallFromDtoWall(WallDto dtoWall, float pixelToUnityUnitScale, Vector3 wallCenterLocation, IUnityMainThreadDispatcher unityMainThreadDispatcher) { return(new UcWall(dtoWall.Name, dtoWall.Width, dtoWall.Height, new ObservableCollection <UcSourceInstance>(), pixelToUnityUnitScale, wallCenterLocation, unityMainThreadDispatcher, dtoWall.Id)); }
public ActionResult ShowMessagesWall(int wallId) { WallDto wallDto = pageService.GetWallDto(wallId); return(PartialView("Wall", wallDto)); }
public ActionResult ShowAlbumWall(WallDto wall) { return(PartialView("Wall", wall)); }
public ActionResult CreateAccount(UserViewModel model, HttpPostedFileBase imageFile) { // init db Db db = new Db(); // check model state if (!ModelState.IsValid) { return(View("Index", model)); } // make sure username is unique if (db.Users.Any(x => x.Username.Equals(model.Username))) { ModelState.AddModelError("", "Username" + model.Username + " is taken."); model.Username = ""; return(View("Index", model)); } // create user dto UserDTO userDTO = new UserDTO() { FirstName = model.FirstName, LastName = model.LastName, EmailAddress = model.EmailAddress, Username = model.Username, Password = model.Password }; // add to DTO db.Users.Add(userDTO); // save db.SaveChanges(); // get inserted id int userId = userDTO.Id; // login user FormsAuthentication.SetAuthCookie(model.Username, false); // set uploads directory var uploadsDir = new DirectoryInfo(string.Format("{0}Uploads", Server.MapPath(@"\"))); // check if file was uploaded if (imageFile != null && imageFile.ContentLength > 0) { // get extension string ext = imageFile.ContentType.ToLower(); // verify extension if (ext != "image/jpg" && ext != "image/jpeg" && ext != "image/pjpeg" && ext != "image/gif" && ext != "image/x-png" && ext != "image/png") { ModelState.AddModelError("", "The image was not uploaded - wrong image extension."); return(View("Index", model)); } // set image name - the user's id w/the jpg extension string imageName = userId + "jpg"; // set image path var path = string.Format("{0}\\{1}", uploadsDir, imageName); // save image imageFile.SaveAs(path); } // add to wall WallDto wall = new WallDto(); wall.Id = userId; wall.Message = ""; wall.DateEdited = DateTime.Now; db.Wall.Add(wall); db.SaveChanges(); // redirect return(Redirect("~/" + model.Username)); }
public ActionResult Username(string username = "") { // init db Db db = new Db(); // check if user exists if (!db.Users.Any(x => x.Username.Equals(username))) { return(Redirect("Index")); } // viewbag username ViewBag.Username = username; // get logged in user's username string user = User.Identity.Name; // viewbag user's full name UserDTO userDTO = db.Users.Where(x => x.Username.Equals(user)).FirstOrDefault(); ViewBag.FullName = userDTO.FirstName + " " + userDTO.LastName; // get user's id int userId = userDTO.Id; // ViewBag user's id ViewBag.UserId = userId; // get viewing full name UserDTO userDTO2 = db.Users.Where(x => x.Username.Equals(username)).FirstOrDefault(); ViewBag.ViewingFullName = userDTO2.FirstName + " " + userDTO2.LastName; // get username's image ViewBag.UsernameImage = userDTO2.Username + ".jpg"; // viewbag user type string userType = "guest"; if (username.Equals(user)) { userType = "owner"; } ViewBag.UserType = userType; // check friend status if (userType == "guest") { UserDTO user1 = db.Users.Where(x => x.Username.Equals(user)).FirstOrDefault(); int id1 = user1.Id; UserDTO user2 = db.Users.Where(x => x.Username.Equals(username)).FirstOrDefault(); int id2 = user2.Id; FriendDto friend1 = db.Friends.Where(x => x.User1 == id1 && x.User2 == id2).FirstOrDefault(); FriendDto friend2 = db.Friends.Where(x => x.User2 == id1 && x.User1 == id2).FirstOrDefault(); if (friend1 == null && friend2 == null) { ViewBag.NotFriends = "True"; } if (friend1 != null) { if (!friend1.Active) { ViewBag.NotFriends = "Pending"; } } if (friend2 != null) { if (!friend2.Active) { ViewBag.NotFriends = "Pending"; } } } // get friend request count var friendRequests = db.Friends.Count(x => x.User2 == userId && x.Active == false); if (friendRequests > 0) { ViewBag.FriendRequest = friendRequests; } /*** GET FRIENDS COUNT ***/ // get Id of user whose page is being viewed UserDTO userDto = db.Users.Where(x => x.Username.Equals(username)).FirstOrDefault(); int usernameId = userDto.Id; var friendCount = db.Friends .Count(x => x.User2 == usernameId && x.Active == true || x.User1 == usernameId && x.Active == true); ViewBag.FriendCount = friendCount; // Get message count var messageCount = db.Messages.Count(x => x.To == userId && x.Read == false); ViewBag.MessageCount = messageCount; // viewBag user wall WallDto wall = new WallDto(); ViewBag.WallMessage = db.Wall.Where(x => x.Id == userId).Select(x => x.Message).FirstOrDefault(); // ViewBag friend walls List <int> friendsIds1 = db.Friends.Where(x => x.User1 == userId && x.Active == true) .ToArray().Select(x => x.User2).ToList(); List <int> friendsIds2 = db.Friends.Where(x => x.User2 == userId && x.Active == true) .ToArray().Select(x => x.User1).ToList(); List <int> allFriendIds = friendsIds1.Concat(friendsIds2).ToList(); List <WallViewModel> walls = db.Wall.Where(x => allFriendIds.Contains(x.Id)) .ToArray().OrderByDescending(x => x.DateEdited).Select(x => new WallViewModel(x)).ToList(); ViewBag.Walls = walls; return(View()); }