public User Create(User user, string password) { // validation if (string.IsNullOrWhiteSpace(password)) { throw new Exception("Password is required"); } if (!IsValidEmail(user.EmailAddress)) { throw new Exception("Please enter a valid email address"); } if (_context.Users.Any(x => x.EmailAddress == user.EmailAddress)) { throw new Exception("Email address \"" + user.EmailAddress + "\" is already registered"); } byte[] passwordHash, passwordSalt; CreatePasswordHash(password, out passwordHash, out passwordSalt); user.PasswordHash = passwordHash; user.PasswordSalt = passwordSalt; _context.Users.Add(user); _context.SaveChanges(); return(user); }
public Profile Create(int userId, DateTime dateOfBirth, Address address, string rating, string bio, int clubId) { var user = _userService.GetById(userId); var club = _clubService.GetById(clubId); Enum.TryParse(rating, true, out Rating parsedRating); var profile = new Profile { User = user, DateOfBirth = dateOfBirth, Address = address, Rating = parsedRating, Club = club, Available = true, Bio = bio }; var duplicatedAddress = _addressService.GetByUniqueIdentifier(profile.Address.UniqueIdentifier); if (duplicatedAddress == null) { _context.Profiles.Add(profile); } else { profile.Address = null; _context.Profiles.Add(profile); profile.Address = duplicatedAddress; } _context.SaveChanges(); return(profile); }
public Address Create(Address address) { _context.Addresses.Add(address); _context.SaveChanges(); return(address); }
public Friend Accept(int requestedById, int requestedToId) { var friend = GetById(requestedById, requestedToId); if (friend == null) { throw new Exception("Friend request not found"); } friend.FriendRequestFlag = FriendRequestFlag.Approved; friend.BecameFriendsTime = DateTime.Now; _context.Friends.Update(friend); _context.SaveChanges(); return(friend); }