Exemplo n.º 1
0
 public Rating(Deal aboutDeal, User aboutUser, bool isPositive)
 {
     AboutDeal = aboutDeal.Id;
     AboutUser = aboutUser.Id;
     IsPositive = isPositive;
     ExpirationDate = aboutDeal.ExpirationDate;
 }
Exemplo n.º 2
0
 public void TestUserEquality()
 {
     var u1 = new User("bla", "pass");
     var u2 = new User("bla", "pass");
     var u3 = new User("notbla", "notpass");
     Assert.That(u1, Is.EqualTo(u2));
     Assert.That(u1, Is.Not.EqualTo(u3));
 }
Exemplo n.º 3
0
 public Deal ToDeal(User postedBy)
 {
     return new Deal
     {
         ProductName = ProductName,
         StoreName = StoreName,
         Price = Price,
         ExpirationDate = ExpirationDate,
         ZipCode = ZipCode,
         UserPostedBy = postedBy.Id
     };
 }
Exemplo n.º 4
0
 private async Task AddUser(User user)
 {
     try
     {
         await userCollection.InsertOneAsync(user);
     }
     catch (MongoWriteException ex)
     {
         if (ex.Message.Contains("E11000"))
         {
             throw new AlreadyExistsException("A user with the same name has already been added.", ex);
         }
     }
 }
Exemplo n.º 5
0
        public async Task RateDeal(Deal whatDeal, User asUser, bool isPositive)
        {
            //find a rating if it already exists, if not, make a new rating
            var filterD = Builders<Rating>.Filter.Eq("AboutDeal", whatDeal.Id);
            var filterU = Builders<Rating>.Filter.Eq("AboutUser", asUser.Id);
            var filterFinal = filterD & filterU;

            var updateDef = Builders<Rating>.Update
                .Set("AboutDeal", whatDeal.Id)
                .Set("AboutUser", asUser.Id)
                .Set("IsPositive", isPositive)
                .Set("ExpirationDate", whatDeal.ExpirationDate);
            await ratingCollection.UpdateOneAsync(filterFinal, updateDef, new UpdateOptions { IsUpsert = true });
        }
Exemplo n.º 6
0
 public async Task RegisterUser(string desiredName, string password)
 {
     var storedHash = PasswordStorage.Hash(password);
     var thisUser = new User(desiredName, storedHash);
     await AddUser(thisUser);
 }
Exemplo n.º 7
0
 public void SetPostedBy(User who)
 {
     UserPostedBy = who.Id;
 }
Exemplo n.º 8
0
 private bool Equals(User other)
 {
     return
         string.Equals(Name, other.Name) &&
         string.Equals(PasswordHash, other.PasswordHash);
 }