Beispiel #1
0
 public Rating(Deal aboutDeal, User aboutUser, bool isPositive)
 {
     AboutDeal = aboutDeal.Id;
     AboutUser = aboutUser.Id;
     IsPositive = isPositive;
     ExpirationDate = aboutDeal.ExpirationDate;
 }
 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));
 }
Beispiel #3
0
 public Deal ToDeal(User postedBy)
 {
     return new Deal
     {
         ProductName = ProductName,
         StoreName = StoreName,
         Price = Price,
         ExpirationDate = ExpirationDate,
         ZipCode = ZipCode,
         UserPostedBy = postedBy.Id
     };
 }
Beispiel #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);
         }
     }
 }
        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 });
        }
Beispiel #6
0
 public async Task RegisterUser(string desiredName, string password)
 {
     var storedHash = PasswordStorage.Hash(password);
     var thisUser = new User(desiredName, storedHash);
     await AddUser(thisUser);
 }
Beispiel #7
0
 public void SetPostedBy(User who)
 {
     UserPostedBy = who.Id;
 }
Beispiel #8
0
 private bool Equals(User other)
 {
     return
         string.Equals(Name, other.Name) &&
         string.Equals(PasswordHash, other.PasswordHash);
 }