/// <summary> /// Add a new category to the database /// </summary> /// <param name="category"></param> public void AddCategory(Category category) { var entity = _context.Category.FirstOrDefault(c => c.CategoryName == category.CategoryName); if (entity == null) { _context.Category.Add(category); _context.SaveChanges(); } }
/// <summary> /// Add a user image to the database /// </summary> /// <param name="userImage"></param> public void AddUserImage(UserImage userImage) { var entity = _context.UserImage.FirstOrDefault(ui => ui.UserId == userImage.UserId); if (entity == null) { _context.UserImage.Add(userImage); _context.SaveChanges(); } }
/// <summary> /// /// </summary> /// <param name="groupImage"></param> public void AddGroupImage(GroupImage groupImage) { var entity = _context.GroupImage.FirstOrDefault(gi => gi.GroupId == groupImage.GroupId); if (entity == null) { _context.GroupImage.Add(groupImage); _context.SaveChanges(); } }
/// <summary> /// Add an interest to the database /// </summary> /// <param name="interest"></param> public void AddInterest(Interest interest) { var entity = _context.Interest.FirstOrDefault(i => i.InterestName == interest.InterestName); if (entity != null) { _context.Interest.Add(interest); _context.SaveChanges(); } }
/// <summary> /// Adds a friend request to the database /// </summary> /// <param name="userId"></param> /// <param name="pendingId"></param> public void AddFriendRequest(int userId, int pendingId) { var entity = _context.UserHasFriendRequest.FirstOrDefault(uhfr => (uhfr.UserId == userId && uhfr.PendingFriendId == pendingId) || (uhfr.PendingFriendId == userId && uhfr.UserId == pendingId)); if (entity == null) { _context.UserHasFriendRequest.Add(new UserHasFriendRequest { UserId = userId, PendingFriendId = pendingId }); _context.SaveChanges(); } }
/// <summary> /// Adds a group to the database /// </summary> /// <param name="group"></param> public int AddGroup(Group group) { if (group != null) { _context.Group.Add(group); _context.GroupHasActivity.Add(new GroupHasActivity { GroupId = group.GroupId, UserId = group.OwnerId, Type = "CREATION", CreationDate = group.CreationDate }); _context.SaveChanges(); } return(group.GroupId); }
/// <summary> /// Adds a group comment to the database /// </summary> /// <param name="groupComment"></param> /// <returns></returns> public int AddGroupComment(GroupComment groupComment) { if (groupComment != null) { _context.GroupComment.Add(groupComment); if (groupComment.ParentId != null) { var entity = _context.GroupComment.FirstOrDefault(gc => gc.GroupCommentId == groupComment.ParentId); if (!entity.HasChildren) { entity.HasChildren = true; _context.GroupComment.Update(entity); } } _context.SaveChanges(); } return(groupComment.GroupCommentId); }
/// <summary> /// Add a new user to the database /// </summary> /// <param name="user"></param> public void AddUser(User user) { _context.User.Add(user); _context.SaveChanges(); }