public Result<User> CreateUser(string email, string password, string confirmPassword) { var emailValidatorResult = _emailValidatorService.IsEmailValid(email); if (emailValidatorResult.Success == false) { return Failure<User>(emailValidatorResult.BusinessRuleViolated); } var passwordValidatorResult = _passwordValidatorService.IsPasswordValid(password); if (passwordValidatorResult.Success == false) { return Failure<User>(passwordValidatorResult.BusinessRuleViolated); } if (password.Equals(confirmPassword) == false) { return Failure<User>(BusinessRules.PasswordMustBeEqualToConfirmPassword); } if(_userRepository.UserAlreadyExists(email)) return Failure<User>(BusinessRules.UserAlreadyExists); User user = new User() { Email = email, PasswordHash = _hasherService.Hash(password).ResultObject }; _userRepository.Add(user); return Success(user); }
public Request(User user, Package package, Location origin, Location destination) { this.Destination = destination; this.RequestedUser = user; this.Origin = origin; this.Package = package; }
public void TestAddNegativeNote() { User user1 = new User(); user1.FirstName = "AAA2"; user1.LastName = "AAA2"; user1.Email = "[email protected]"; User user2 = userService.GetUserByEmail("*****@*****.**"); Category category = categoryService.GetCategoryByName("category"); Product product = new Product(); product.Name = "BBBB2"; product.Description = "BBBB2"; product.Categories.Add(category); userService.AddUser(user1); productService.AddProduct(product); //currencyService.AddCurrency("RON"); Currency currency = currencyService.getCurrencyById(1); Role role = roleService.GetRoleByName(Constants.ACTIONEER); userService.AddRoleToUser("[email protected]", role); auctionService.AddNewAuction(user2, product, currency, 100, DateTime.Now, new DateTime(2015, 10, 18)); productAuctionService.AddProductAuction(user1, product, 101, currency); bool ok = userService.AddNoteToUser(user1, user2, -1); }
public void AddUser(User user) { using(var context = new AuctionModelContainer()) { context.Users.Add(user); context.SaveChanges(); } }
public static void AddAuction() { Auction auction = new Auction(); User user = new User(); Product product = new Product(); auction.Product = product; IAuctionService auctionService = new AuctionService(); auctionService.AddNewAuction(auction, user); }
public int GetNumberOfActiveAuctionsStartedByUser(User user) { using(var context = new AuctionModelContainer()) { int nr = (from auction in context.Auctions where auction.User.Email.Equals(user.Email) select auction).Count(); return nr; } }
public void SaveUser(DomainModel.User user) { EFRepo.Model.UserDB createdUser = new EFRepo.Model.UserDB(); var t = Mapper.Map <User, UserDB>(user); createdUser.FirstName = user.FirstName; createdUser.LastName = user.LastName; createdUser.Login = user.Login; Registration.UserRepository.Create(createdUser); }
public void AddRoleToUser(User user,Role role) { using(var context = new AuctionModelContainer()) { context.setLazyFalse(); context.Users.Attach(user); context.Roles.Attach(role); context.Entry(user).Collection(u => u.Roles).Load(); user.Roles.Add(role); context.SaveChanges(); } }
public bool AddNoteToUser(User givingNoteUser, User receivingNoteUser, int note) { try { VerifyUsers(givingNoteUser, receivingNoteUser); logger.logInfo("User " + givingNoteUser.Email + " try to add note " + note + " to user with email " + receivingNoteUser); if (!VerifyUsersAuctions(givingNoteUser, receivingNoteUser)) throw new AuctionException("User "+givingNoteUser.Email+" can not add a note to user "+receivingNoteUser.Email+" because it does not participate to any auction"); ICollection<User> users = DataMapperFactoryMethod.GetCurrentFactory().UserFactory.GetAllUsersThatGiveARaitingToAUser(receivingNoteUser); foreach(User user in users) if(user.Equals(givingNoteUser)) throw new AuctionException("User " + givingNoteUser.Email + " can not add a note to user " + receivingNoteUser.Email + " because it already give a note to that user"); Rating persistRating = new Rating(); persistRating.Date = DateTime.Now; persistRating.GivingNoteUser = givingNoteUser; persistRating.ReceivingNoteUser = receivingNoteUser; persistRating.Grade = note; DataMapperFactoryMethod.GetCurrentFactory().UserFactory.AddRating(persistRating); logger.logInfo("User " + givingNoteUser.Email + " succesfully add note " + note + " to user with email " + receivingNoteUser); return true; } catch (EntityDoesNotExistException exc) { logger.logError(exc); throw exc; } catch(ValidationException validationException) { logger.logError(validationException); throw validationException; } catch(AuctionException auctioException) { logger.logError(auctioException); throw auctioException; } }
public bool closeAuction(User user, Product product) { logger.logInfo("Try to close a auction"); try { DataMapperFactoryMethod.GetCurrentFactory().ProductAuctionFactory.closeAuction(user, product); } catch (EntityDoesNotExistException exc) { logger.logError(exc); throw exc; } catch (AuctionException exc) { logger.logError(exc); throw exc; } return true; }
public bool AddProductAuction(User user, Product product, double price, Currency currency) { logger.logInfo("Try to add a new ProductAuction"); try { DataMapperFactoryMethod.GetCurrentFactory().ProductAuctionFactory.AddProductAuction(user, product, price, currency); return true; } catch (ValidationException validationException) { logger.logError(validationException); throw validationException; } catch (EntityDoesNotExistException entity) { logger.logError(entity); throw entity; } }
public void AddNewAuction(User user,Product product,Currency currency,double startPrice,DateTime startDate,DateTime endDate) { try { logger.logInfo("User "+user.Email+" try to add a new auction."); CheckUser(user); CheckProduct(product,user); Auction auction = new Auction(); auction.User = user; auction.Product = product; auction.Currency = currency; auction.StartPrice = startPrice; auction.BeginDate = startDate; auction.EndDate = endDate; var validationResults = Validation.Validate<Auction>(auction); if (!validationResults.IsValid) { throw new ValidationException("Invalid auction"); } DataMapperFactoryMethod.GetCurrentFactory().AuctionFactory.AddNewAuction(auction); } catch (EntityDoesNotExistException exc) { logger.logError(exc); throw exc; } catch (ValidationException validationException) { logger.logError(validationException); throw validationException; } catch (AuctionException auctioException) { logger.logError(auctioException); throw auctioException; } }
public ICollection<Role> GetAllRolesOfAnUser(User user) { using(var context = new AuctionModelContainer()) { var roleVar = (from role in context.Roles select role).ToList(); for (int i = 0; i < roleVar.Count;i++ ) { ICollection<User> users = roleVar.ElementAt(i).Users; bool ok = false; foreach (User userFor in users) if (userFor.Email.Equals(user.Email)) ok = true; if (!ok) { roleVar.Remove(roleVar.ElementAt(i)); i--; } } return roleVar; } }
public void ShouldAcceptSelectedMatchedRequestsAndChangeStatusOfTheRequests() { var matchRepositoryMock = new Mock<IMatchRepository> { }; var userRepositoryMock = new Mock<IUserRepository> {}; List<Match> matchedRequests = new List<Match>(); Request request = new Request(); User user = new User(); user.Email = new Email("*****@*****.**"); Match match = new Match(new Journey(), request); match.Status = MatchStatus.Potential; match.Id = 1; matchedRequests.Add(match); matchRepositoryMock.Setup(ps => ps.LoadPotentialMatchesByUserJourney("*****@*****.**")).Returns(matchedRequests); userRepositoryMock.Setup(ps => ps.LoadUser("*****@*****.**")).Returns(user); Website.Controllers.RequestMatchController requestMatchController = new Website.Controllers.RequestMatchController(matchRepositoryMock.Object,userRepositoryMock.Object ,"*****@*****.**"); requestMatchController.AcceptRequest(new string[]{"1"}); Assert.AreEqual(match.Status,MatchStatus.Accepted); Assert.AreEqual(match.Request.AcceptingUser,user); matchRepositoryMock.Verify(ps => ps.UpdateMatches(matchedRequests)); }
public Rating GetRating(User givingRating,User receivingRating) { return DataMapperFactoryMethod.GetCurrentFactory().UserFactory.GetRating(givingRating,receivingRating); }
public bool AddUser(User user) { logger.logInfo("Try to add a new user."); try { User oldUser = GetUserByEmail(user.Email); if (oldUser != null) throw new DuplicateException("You can not add two users with the same email (" + user.Email + ")."); var validationResults = Validation.Validate<User>(user); if (!validationResults.IsValid) { String message = "Invalid fields for user "+user.Email; throw new ValidationException(message); } DataMapperFactoryMethod.GetCurrentFactory().UserFactory.AddUser(user); logger.logInfo("The user with name " + user.FirstName +" "+user.LastName+ " was succesfully added."); return true; } catch (ValidationException validationException) { logger.logError(validationException); throw validationException; } catch (DuplicateException duplicateException) { logger.logError(duplicateException); throw duplicateException; } }
public Result<bool> RemoveUser(User user) { _userRepository.Remove(user); return Success(true); }
public ICollection<Rating> GetAllRatingsOfAnUser(User user) { return DataMapperFactoryMethod.GetCurrentFactory().UserFactory.GetAllRatingsOfAnUser(user); }
public ICollection<Role> GetRolesFromAnUser(User user) { return DataMapperFactoryMethod.GetCurrentFactory().RoleFactory.GetAllRolesOfAnUser(user); }
public Journey(User traveller, Location origin, Location destination) { this.Traveller = traveller; this.Destination = destination; this.Origin = origin; }
public void TestAddNewAuctionByAUserWithBadRating() { User user1 = userService.GetUserById(1); User user2 = new User(); user2.FirstName = "CCC"; user2.LastName = "CCC"; user2.Email = "[email protected]"; userService.AddUser(user2); userService.AddRoleToUser("[email protected]", roleService.GetRoleByName(Constants.ACTIONEER)); Category category = categoryService.GetCategoryById(1); Product product = new Product(); product.Name = "AAA3"; product.Description = "AAAAAAAA3"; product.Categories.Add(category); productService.AddProduct(product); Currency currency = currencyService.GetCurrencyByName("RON"); auctionService.AddNewAuction(user1, product, currency, 100, DateTime.Now, DateTime.Now); productAuctionService.AddProductAuction(user2, product, 500, currency); userService.AddNoteToUser(user2, user1, 1); product = new Product(); product.Name = "AAA4"; product.Description = "AAAAAAAA4"; product.Categories.Add(category); productService.AddProduct(product); auctionService.AddNewAuction(user1, product, currency, 100, DateTime.Now, DateTime.Now); }
private void VerifyUsers(User givingNoteUser, User receivingNoteUser) { if (givingNoteUser == null) throw new EntityDoesNotExistException("User which give the note must not be null"); User findedUser = this.GetUserByEmail(givingNoteUser.Email); if (findedUser == null) throw new EntityDoesNotExistException("User which give the note does not exist"); if (receivingNoteUser == null) throw new EntityDoesNotExistException("User which receive the note must not be null"); findedUser = this.GetUserByEmail(receivingNoteUser.Email); if (findedUser == null) throw new EntityDoesNotExistException("User which receive the note does not exist"); if (givingNoteUser.Equals(receivingNoteUser)) throw new AuctionException("User " + givingNoteUser.Email + " can not add a note because it try to add a note to him"); }
private void CheckUser(User user) { IRoleService roleService = new RoleService(); IConfiguration configuration = ConfigurationService.GetInstance(); IUserService userService = new UserService(); ICollection<Role> roles = roleService.GetRolesFromAnUser(user); ICollection<Rating> ratings = userService.GetAllRatingsOfAnUser(user); bool ok = false; foreach (Role role in roles) if (role.Name.Equals(Constants.OWNER)) ok = true; if (!ok) throw new AuctionException("User " + user.Email + " does not have the rights to add an auction"); int nrOfActiveAuctions = this.GetNumberOfActiveAuctionsStartedByUser(user); int sum = 0; int nr = 0; DateTime maxDate = new DateTime(1000, 1, 1); foreach (Rating rating in ratings) { if ((DateTime.Now - rating.Date).TotalDays < configuration.GetValue(Constants.NR_OF_DAYS_USED_TO_DETERMINE_RATING)) { sum += rating.Grade; nr++; if (rating.Date > maxDate) maxDate = rating.Date; } } double ratingCalc, maxNrOfAuctions; if(nr > 0) { ratingCalc = sum / nr; maxNrOfAuctions = ratingCalc / 10 * configuration.GetValue(Constants.MAX_NR_OF_STARTED_AUCTION); } else { ratingCalc = 10; maxNrOfAuctions = configuration.GetValue(Constants.MAX_NR_OF_STARTED_AUCTION); } int intMaxNrOfAuctions = (int)maxNrOfAuctions; if(ratingCalc < configuration.GetValue(Constants.RATING_THRESH_HOLD_FOR_AUCTION)) { if((DateTime.Now - maxDate).Days >= configuration.GetValue(Constants.NR_OF_DAY_BEFORE_RATING_RESET)) { for(int i=0;i<ratings.Count;i++) { DataMapperFactoryMethod.GetCurrentFactory().UserFactory.RemoveRating(ratings.ElementAt(i)); } } else throw new AuctionException("Auction can not be added because the rating of the user is small than " + configuration.GetValue(Constants.RATING_THRESH_HOLD_FOR_AUCTION) + "resetare"); } if (nrOfActiveAuctions > intMaxNrOfAuctions) throw new AuctionException("Auction can not be added because max number of auctions per user is "+configuration.GetValue(Constants.MAX_NR_OF_STARTED_AUCTION)); }
public virtual bool Equals(User other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return other.Email.Equals(Email); }
public void TestGetRolesFromAnUserWithRoles() { User user = new User(); user.FirstName = "AAA"; user.LastName = "BBB"; user.Email = "*****@*****.**"; userService.AddUser(user); Role role = new Role(); role.Name = "testrole"; roleService.AddRole(role); userService.AddRoleToUser("*****@*****.**", role); ICollection<Role> roles = roleService.GetRolesFromAnUser(userService.GetUserByEmail("*****@*****.**")); Assert.AreEqual(1, roles.Count); }
public int GetNumberOfActiveAuctionsStartedByUser(User user) { return DataMapperFactoryMethod.GetCurrentFactory().AuctionFactory.GetNumberOfActiveAuctionsStartedByUser(user); }
private bool VerifyUsersAuctions(User givingNoteUser, User receivingNoteUser) { ICollection<Auction> auctions = receivingNoteUser.Auctions; foreach(Auction auction in auctions) { ICollection<User> users = DataMapperFactoryMethod.GetCurrentFactory().UserFactory.GetAllUsersThatParticipateToAnAuction(auction); foreach (User user in users) { if (user.Equals(givingNoteUser)) return true; } } return false; }
public void TestAddLicitation() { User user1 = new User(); user1.FirstName = "AAA"; user1.LastName = "AAA"; user1.Email = "[email protected]"; User user2 = new User(); user2.FirstName = "BBB"; user2.LastName = "BBB"; user2.Email = "[email protected]"; Role role1 = new Role(); role1.Name = Constants.OWNER; Role role2 = new Role(); role2.Name = Constants.ACTIONEER; Category category = new Category(); category.Name = "category"; category.Description = "AAAAA"; categoryService.AddCategory(category); Product product = new Product(); product.Name = "AAA"; product.Description = "AAAAAAAA"; product.Categories.Add(category); userService.AddUser(user1); userService.AddUser(user2); productService.AddProduct(product); currencyService.AddCurrency("RON"); Currency currency = currencyService.GetCurrencyByName("RON"); roleService.AddRole(role1); roleService.AddRole(role2); userService.AddRoleToUser("[email protected]", role1); userService.AddRoleToUser("[email protected]", role2); auctionService.AddNewAuction(user1, product, currency, 100, DateTime.Now, DateTime.Now); productAuctionService.AddProductAuction(user2, product, 200, currency); userService.AddNoteToUser(user2, user1, 7); }
public bool UpdateRating(User givingRating,User receivingRating, int note) { try { if (givingRating == null) throw new EntityDoesNotExistException("User which give the note must not be null"); User findedUser = this.GetUserByEmail(givingRating.Email); if (findedUser == null) throw new EntityDoesNotExistException("User which give the note does not exist"); if (receivingRating == null) throw new EntityDoesNotExistException("User which receive the note must not be null"); findedUser = this.GetUserByEmail(receivingRating.Email); if (findedUser == null) throw new EntityDoesNotExistException("User which receive the note does not exist"); Rating oldRating = this.GetRating(givingRating,receivingRating); if (oldRating == null) throw new AuctionException("The rating gived by user "+givingRating.Email+" to user "+receivingRating.Email+" does not exist"); oldRating.Grade = note; DataMapperFactoryMethod.GetCurrentFactory().UserFactory.UpdateRating(oldRating); return true; } catch (EntityDoesNotExistException exc) { logger.logError(exc); throw exc; } catch (ValidationException validationException) { logger.logError(validationException); throw validationException; } catch (AuctionException auctioException) { logger.logError(auctioException); throw auctioException; } }
private void CheckProduct(Product product,User user) { ICategoryService categoryService = new CategoryService(); IProductService productService = new ProductService(); IConfiguration configuration = ConfigurationService.GetInstance(); ICollection<Category> categorys = categoryService.GetCategorysForAProduct(product); int nrOfAuctions = 0; foreach(Category category in categorys) { ICollection<Category> parentCAtegorys = categoryService.getParents(category.IdCategory); ICollection<Product> products; foreach(Category parentCategory in parentCAtegorys) { products = productService.GetAllProductsOfACategory(category); foreach(Product productCat in products) { Auction auction = productService.GetAuctionOfAProduct(productCat); if (auction != null && auction.User.Equals(user)) nrOfAuctions++; } } } if(nrOfAuctions >= configuration.GetValue(Constants.MAX_NR_OF_AUCTION_ASSOCIATE_WITH_CATEGORY)) throw new AuctionException("The auction can not be added because the number of auctions per category was exceeded"); }
public void TestGetRolesFromAnUser() { User user = new User(); user.FirstName = "AAA"; user.LastName = "BBB"; user.Email = "*****@*****.**"; userService.AddUser(user); ICollection<Role> roles = roleService.GetRolesFromAnUser(userService.GetUserByEmail("*****@*****.**")); Assert.AreEqual(0, roles.Count); }