Task IUserService.ConfirmUserEmail(string userId, string confirmationToken, IValidationErrorNotifier errors) { Contract.Requires(!String.IsNullOrWhiteSpace(userId)); Contract.Requires(!String.IsNullOrWhiteSpace(confirmationToken)); Contract.Requires(errors != null); throw new NotImplementedException(); }
Task IAuctionService.Buyout(int auctionId, string buyerId, IValidationErrorNotifier errors) { Contract.Requires(auctionId > 0); Contract.Requires(buyerId != null); Contract.Requires(errors != null); throw new NotImplementedException(); }
Task IUserService.AddUser(User user, string password, IValidationErrorNotifier errors) { Contract.Requires(user != null); Contract.Requires(password != null); Contract.Requires(errors != null); throw new NotImplementedException(); }
Task IUserService.ResetUserPassword(string userName, string newPassword, string resetToken, IValidationErrorNotifier errors) { Contract.Requires(!String.IsNullOrWhiteSpace(userName)); Contract.Requires(!String.IsNullOrWhiteSpace(newPassword)); Contract.Requires(!String.IsNullOrWhiteSpace(resetToken)); Contract.Requires(errors != null); throw new NotImplementedException(); }
Task IUserService.UpdateUserPassword(string userId, string currentPassword, string newPassword, IValidationErrorNotifier errors) { Contract.Requires(!String.IsNullOrWhiteSpace(userId)); Contract.Requires(!String.IsNullOrWhiteSpace(currentPassword)); Contract.Requires(!String.IsNullOrWhiteSpace(newPassword)); Contract.Requires(errors != null); throw new NotImplementedException(); }
public async Task MoveAuction(int auctionId, int newCategoryId, string movingUserId, IValidationErrorNotifier errors) { var auction = await this.GetById(auctionId); if(!await CanBeMoved(auction, movingUserId)) { errors.AddError(Lang.Show.CannotMove); return; } auction.CategoryId = newCategoryId; await mContext.SaveChangesAsync(); }
public async Task Buyout(int auctionId, string buyerId, IValidationErrorNotifier errors) { var auction = await GetById(auctionId); if(!auction.IsBuyoutEnabled) { errors.AddError(Lang.Buy.BuyoutNotEnabled); return; } if(!CanBeBought(auction, buyerId, errors)) return; auction.Offers.Add(new BuyOffer { UserId = buyerId, Date = DateTime.Now, Amount = auction.BuyoutPrice.Amount, }); await mContext.SaveChangesAsync(); await mUserNotifier.NotifyAuctionSold(auction.Seller, auction); await mUserNotifier.NotifyAuctionWon(auction.Buyer, auction); }
public async Task Bid(int auctionId, string buyerId, decimal bidAmount, IValidationErrorNotifier errors) { var auction = await GetById(auctionId); if(!auction.IsBiddingEnabled) { errors.AddError(Lang.Buy.BiddingNotEnabled); return; } if(!CanBeBought(auction, buyerId, errors)) return; if(bidAmount < auction.MinBidAllowed) { errors.AddError(String.Format(Lang.Buy.TooLowBid, new Money(auction.MinBidAllowed, auction.MinimumPrice.Currency))); return; } var previouslyBestOffer = auction.BestOffer; var userOffer = new BuyOffer { UserId = buyerId, Date = DateTime.Now, Amount = bidAmount, }; auction.Offers.Add(userOffer); await mContext.SaveChangesAsync(); await mUserNotifier.NotifyOfferAdded(userOffer.User, userOffer, auction); if(previouslyBestOffer != null) { await mUserNotifier.NotifyOutbid(previouslyBestOffer.User, auction); } }
private bool CanBeBought(Auction auction, string buyerId, IValidationErrorNotifier errors) { if(auction.Status != AuctionStatus.Active) { errors.AddError(Lang.Buy.AuctionIsInactive); return false; } if(auction.SellerId == buyerId) { errors.AddError(Lang.Buy.CannotBuyOwnAuctions); return false; } return true; }
public async Task RemoveAuctions(IReadOnlyCollection<int> ids, string removingUserId, IValidationErrorNotifier errors) { var auctions = await mContext.Auctions.Include(x => x.Offers).Where(x => ids.Contains(x.Id)).ToListAsync(); if(!await auctions.All(async x => await CanBeRemoved(x, removingUserId, errors))) return; await mContext.Auctions.Where(x => ids.Contains(x.Id)).DeleteAsync(); foreach(var auctionId in ids) { RemoveAuctionPhotos(auctionId); } }
private async Task<bool> CanBeRemoved(Auction auction, string userId, IValidationErrorNotifier errors) { if(auction.SellerId != userId && !await mUserService.IsUserInRole(userId, "Admin")) { errors.AddError(Lang.Delete.WrongUser); return false; } if(auction.Offers.Any()) { errors.AddError(Lang.Delete.BuyOfferHasBeenMade); return false; } if(auction.Status != AuctionStatus.Active) { errors.AddError(Lang.Delete.AuctionIsInactive); return false; } return true; }
Task IAuctionService.RemoveAuctions(IReadOnlyCollection<int> ids, string removingUserId, IValidationErrorNotifier errors) { Contract.Requires(removingUserId != null); Contract.Requires(ids != null); Contract.Requires(errors != null); throw new NotImplementedException(); }
Task IAuctionService.MoveAuction(int auctionId, int newCategoryId, string movingUserId, IValidationErrorNotifier errors) { Contract.Requires(auctionId > 0); Contract.Requires(newCategoryId > 0); Contract.Requires(movingUserId != null); Contract.Requires(errors != null); throw new NotImplementedException(); }