public void Add(Guid id, string firstName, string lastName, IList<Address> addresses, string password, string confirmPassword, string email) { var customer = _customerRepository.GetByEmail(email); if (customer != null) { throw new EmailExistsException(String.Format("{0} is already existing", email)); } if (password != confirmPassword || password.Length < 1) { throw new InvalidPasswordException("Invalid Password"); } byte[] salt, hash; _passwordHandler.SaltAndHash(password, out salt, out hash); customer = new Customer { Id = id, FirstName = firstName, LastName = lastName, Addresses = addresses, Email = email, PasswordSalt=salt, PasswordHash = hash, Role = Role.Customer }; _customerRepository.Add(customer); }
public void Update(Customer customer) { var oldAddresses = _addressRepository.GetAll(customer.Id); foreach (var address in oldAddresses) _addressRepository.Remove(address.Id); _customerRepository.Update(); }
public void PlaceBid(Guid bidId, Guid auctionId, decimal amount, DateTime bidTime, Customer customer) { var auction = Get(auctionId); if (customer == null) throw new CustomerNotExistException("Customer does not exist"); if (auction == null) throw new AuctionNotExistException(); if (bidTime < auction.StartTime || bidTime > auction.EndTime) throw new BidTimeToEarlyOrToLateException(); if (amount < auction.Product.GetStartPrice()) throw new BidAmountToSmallException(amount, auction.Product.GetStartPrice()); var lastestBid = auction.Bids.OrderBy(b => b.Amount).LastOrDefault(); if (lastestBid != null && amount < lastestBid.Amount) throw new BidAmountToSmallException(amount, lastestBid.Amount); var bid = new Bid { Id = bidId, Customer = customer, Amount = amount, Time = bidTime }; _auctionRespository.AddBid(auction.Id, bid); if (bid.Amount >= auction.AcceptedPrice) { EndAuction(auction.Id); } }