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)); }
public Deal ToDeal(User postedBy) { return new Deal { ProductName = ProductName, StoreName = StoreName, Price = Price, ExpirationDate = ExpirationDate, ZipCode = ZipCode, UserPostedBy = postedBy.Id }; }
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 }); }
public async Task RegisterUser(string desiredName, string password) { var storedHash = PasswordStorage.Hash(password); var thisUser = new User(desiredName, storedHash); await AddUser(thisUser); }
public void SetPostedBy(User who) { UserPostedBy = who.Id; }
private bool Equals(User other) { return string.Equals(Name, other.Name) && string.Equals(PasswordHash, other.PasswordHash); }