public void AddToEvent(long donorId,
                        long eventId,
                        ref IAuctionTransaction trans)
 {
     var rec = new AuctionEventDonorEntity() {EventId = eventId, DonorId = donorId};
     rec.Save();
 }
        public Validation ValidateNewBidder(Bidder bidder, ref IAuctionTransaction trans)
        {
            var val = new Validation();

            if (string.IsNullOrEmpty(bidder.Name))
            {
                val.AddError("Name is empty");
            }

            if (string.IsNullOrEmpty(bidder.Phone))
            {
                val.AddError("Phone number is empty");
            }
            else if (!PhoneNumberIsFormattedCorrectly(bidder.Phone))
            {
                val.AddError("Phone number is not in the correct format");
            }

            if (!_eventRepo.EventExists(bidder.EventId, ref trans))
            {
                val.AddError("Must be in valid auction");
            }

            return val;
        }
 public IList<Auction.Domain.Package> GetByCategory(long categoryId,
                            ref IAuctionTransaction trans)
 {
     using (var records = new PackageCollection())
     {
         var filter = new PredicateExpression(PackageFields.CategoryId == categoryId);
         if (trans != null)
         {
             trans.Add(records);
         }
         records.GetMulti(filter);
         return records.Select(r => new Package()
         {
             BidderId = r.BidderId,
             CategoryId = r.CategoryId,
             ClosedOutBy = r.ClosedOutBy,
             Code = r.Code,
             CreatedBy = r.CreatedBy,
             EndingBid = r.EndingBid,
             EventId = r.EventId,
             Id = r.Id,
             Name = r.Name,
             Notes = r.Notes,
             Paid = (bool)r.Paid,
             StartingBid = r.StartingBid,
             UpdatedBy = r.UpdatedBy
         }).ToList();
     }
 }
 public IList<Auction.Domain.Event> GetByAccount(long accountId,
                           ref IAuctionTransaction trans)
 {
     using (var records = new AuctionEventCollection())
     {
         var filter = new PredicateExpression(AuctionEventFields.AccountId == accountId);
         if (trans != null)
         {
             trans.Add(records);
         }
         records.GetMulti(filter, 0);
         return
             records.Select(
                 b =>
                 new Event()
                     {
                         Id = b.Id,
                         Date = b.Date,
                         Name = b.Name,
                         AccountId = b.AccountId,
                         CreatedBy = b.CreatedBy,
                         Locked = b.Locked,
                         Notes = b.Notes,
                         UpdatedBy = b.UpdatedBy
                     }).ToList();
     }
 }
        public Event Get(long Id, ref IAuctionTransaction trans)
        {
            using (var records = new AuctionEventCollection())
            {
                var filter = new PredicateExpression(AuctionEventFields.Id == Id);

                if (trans != null)
                {
                    trans.Add(records);
                }
                records.GetMulti(filter, 1);
                var b = records.ToList().FirstOrDefault();
                return new Event()
                {
                    Id = Id,
                    Date = b.Date,
                    Name = b.Name,
                    AccountId = b.AccountId,
                    CreatedBy = b.CreatedBy,
                    Locked = b.Locked,
                    Notes = b.Notes,
                    UpdatedBy = b.UpdatedBy
                };
            }
        }
 public Auction.Domain.Package Get(long Id, ref IAuctionTransaction trans)
 {
     using (var records = new PackageCollection())
     {
         var filter = new PredicateExpression(PackageFields.Id == Id);
         if (trans != null)
         {
             trans.Add(records);
         }
         records.GetMulti(filter, 1);
         var r = records.FirstOrDefault();
         return new Package()
                    {
                        BidderId = r.BidderId,
                        CategoryId = r.CategoryId,
                        ClosedOutBy = r.ClosedOutBy,
                        Code = r.Code,
                        CreatedBy = r.CreatedBy,
                        EndingBid = r.EndingBid,
                        EventId = r.EventId,
                        Id = r.Id,
                        Name = r.Name,
                        Notes = r.Notes,
                        Paid = (bool) r.Paid,
                        StartingBid = r.StartingBid,
                        UpdatedBy = r.UpdatedBy
                    };
     }
 }
        public IList<Auction.Domain.Raffle> GetByEvent(long eventId,
                                        ref IAuctionTransaction trans)
        {
            using (var records = new RaffleCollection())
            {
                var filter = new PredicateExpression(RaffleFields.EventId == eventId);

                if (trans != null)
                {
                    trans.Add(records);
                }
                records.GetMulti(filter);
                return records.Select(
                        r =>
                        new Raffle()
                            {
                                CreatedBy = r.CreatedBy,
                                EventId = r.EventId,
                                Id = r.Id,
                                Name = r.Name,
                                Revenue = r.Total,
                                UpdatedBy = (long) r.UpdatedBy
                            }).ToList();
            }
        }
 public void Delete(long donorId,
                    ref IAuctionTransaction trans)
 {
     using(var donors = new DonorCollection())
     {
         donors.DeleteMulti(new PredicateExpression {DonorFields.Id == donorId});
     }
 }
 public void Delete(long Id, ref IAuctionTransaction trans)
 {
     using (var records = new CategoryCollection())
     {
         var filter = new PredicateExpression(CategoryFields.Id == Id);
         if (trans != null)
         {
             trans.Add(records);
         }
         records.DeleteMulti(filter);
     }
 }
 public void DeleteRaffle(long raffleId,
                          ref IAuctionTransaction trans)
 {
     using(var records = new RaffleCollection())
     {
         if(trans != null)
         {
             trans.Add(records);
         }
         records.DeleteMulti(new PredicateExpression(RaffleFields.Id == raffleId));
     }
 }
 public bool EventExists(long id, ref IAuctionTransaction trans)
 {
     using (var records = new AuctionEventCollection())
     {
         var filter = new PredicateExpression(AuctionEventFields.Id == id);
         if (trans != null)
         {
             trans.Add(records);
         }
         return records.GetDbCount(filter) > 0;
     }
 }
 public void Insert(ref Category category, ref IAuctionTransaction trans)
 {
     var c = new CategoryEntity
     {
         AccountId = category.AccountId,
         Name = category.Name
     };
     if (trans != null)
     {
         trans.Add(c);
     }
     c.Save();
 }
 public int GetCountByAccount(long accountId,
                              ref IAuctionTransaction trans)
 {
     using (var records = new AuctionEventCollection())
     {
         var filter = new PredicateExpression(AuctionEventFields.AccountId == accountId);
         if (trans != null)
         {
             trans.Add(records);
         }
         return records.GetDbCount(filter);
     }
 }
        public IList<Category> GetByAccount(long accountId, ref IAuctionTransaction trans)
        {
            using (var records = new CategoryCollection())
            {
                var filter = new PredicateExpression(CategoryFields.AccountId == accountId);

                if (trans != null)
                {
                    trans.Add(records);
                }
                records.GetMulti(filter, 0);
                return records.ToList().Select(c => new Category() { Id = c.Id, Name = c.Name, AccountId = c.AccountId }).ToList();
            }
        }
 public int GetAllowableEventCount(long accountId,
                                   ref IAuctionTransaction trans)
 {
     using (var records = new AccountCollection())
     {
         var filter = new PredicateExpression(AccountFields.Id == accountId);
         if (trans != null)
         {
             trans.Add(records);
         }
         records.GetMulti(filter, 1);
         return records.ToList().First().AllowableEvents;
     }
 }
        public Category Get(long Id, ref IAuctionTransaction trans)
        {
            using (var records = new CategoryCollection())
            {
                var filter = new PredicateExpression(CategoryFields.Id == Id);

                if (trans != null)
                {
                    trans.Add(records);
                }
                records.GetMulti(filter, 1);
                var c = records.ToList().FirstOrDefault();
                return new Category() { Id = c.Id, Name = c.Name, AccountId =  c.AccountId};
            }
        }
        public Auction.Domain.Bidder Get(long Id, ref IAuctionTransaction trans)
        {
            using (var records = new BidderCollection())
            {
                var filter = new PredicateExpression(BidderFields.Id == Id);

                if (trans != null)
                {
                    trans.Add(records);
                }
                records.GetMulti(filter, 1);
                var b = records.ToList().FirstOrDefault();
                return new Bidder() { Id = b.Id, Number = b.Number, Name = b.Name, EventId = b.EventId, Phone = b.Phone };
            }
        }
 public Auction.Domain.Donor GetDonor(long Id, ref IAuctionTransaction trans)
 {
     using (var donors = new DonorCollection())
     {
         donors.GetMulti(new PredicateExpression { DonorFields.Id == Id }, 1);
         return donors.Select(d => new Donor()
         {
             Id = d.Id,
             AccountId = d.AccountId,
             Name = d.Name,
             Notes = d.Notes,
             Phone = d.Phone
         }).First();
     }
 }
        public double GetRaffleTotalRevenueByEvent(long eventId,
                                                   ref IAuctionTransaction trans)
        {
            using (var records = new RaffleCollection())
            {
                var filter = new PredicateExpression(RaffleFields.EventId == eventId);

                if (trans != null)
                {
                    trans.Add(records);
                }
                records.GetMulti(filter);
                return (double) records.ToList().Sum(r => r.Total);
            }
        }
 public long GetMainUserId(long accountId,
                           ref IAuctionTransaction trans)
 {
     using (var records = new AccountCollection())
     {
         var filter = new PredicateExpression(AccountFields.Id == accountId);
         if (trans != null)
         {
             trans.Add(records);
         }
         records.GetMulti(filter, 1);
         return 1;
         // return records.ToList().First().AdminUserId;
     }
 }
        public IList<Auction.Domain.Bidder> GetByEvent(long eventId,
                                ref IAuctionTransaction trans)
        {
            using (var records = new BidderCollection())
            {
                var filter = new PredicateExpression(BidderFields.EventId == eventId);

                if (trans != null)
                {
                    trans.Add(records);
                }
                records.GetMulti(filter, 0);
                return records.ToList().Select(b => new Bidder() { Id = b.Id, Number = b.Number, Name = b.Name, EventId = eventId, Phone = b.Phone }).ToList();
            }
        }
        public Auction.Domain.Raffle Get(long id,
                          ref IAuctionTransaction trans)
        {
            using (var records = new RaffleCollection())
            {
                var filter = new PredicateExpression(RaffleFields.Id == id);

                if (trans != null)
                {
                    trans.Add(records);
                }
                records.GetMulti(filter, 1);
                var b = records.ToList().FirstOrDefault();
                return new Raffle() { Id = id, CreatedBy = b.CreatedBy, EventId = b.EventId, Name = b.Name, Revenue = b.Total, UpdatedBy = (long) b.UpdatedBy};
            }
        }
 public void Update(ref Category category, ref IAuctionTransaction trans)
 {
     using (var records = new CategoryCollection())
     {
         var filter = new PredicateExpression(CategoryFields.Id == category.Id);
         var c = new CategoryEntity
                     {
                         AccountId = category.AccountId,
                         Name = category.Name
                     };
         if (trans != null)
         {
             trans.Add(records);
         }
         records.UpdateMulti(c, filter);
     }
 }
 public void Insert(ref Bidder bidder,
                    ref IAuctionTransaction trans)
 {
     var b = new BidderEntity
                 {
                     Number = bidder.Number,
                     Name = bidder.Name,
                     Phone = bidder.Phone,
                     EventId = bidder.EventId,
                     CreatedBy = bidder.CreatedBy
                 };
     if(trans != null)
     {
         trans.Add(b);
     }
     b.Save();
 }
        public IList<Auction.Domain.Donor> GetByAccount(long accountId,
                                  ref IAuctionTransaction trans)
        {
            using (var donors = new DonorCollection())
            {
                var filter = new PredicateExpression { DonorFields.AccountId == accountId };
                donors.GetMulti(filter);

                return donors.Select(d => new Donor()
                {
                    Id = d.Id,
                    AccountId = d.AccountId,
                    Name = d.Name,
                    Notes = d.Notes,
                    Phone = d.Phone
                }).ToList();
            }
        }
        public Validation ValidateExistingBidder(Bidder bidder, ref IAuctionTransaction trans)
        {
            var val = new Validation();

            if (bidder.Id <= 0)
            {
                val.AddError("Bidder must have an id");
            }
            if (string.IsNullOrEmpty(bidder.Name))
            {
                val.AddError("Name is empty");
            }

            if (string.IsNullOrEmpty(bidder.Phone))
            {
                val.AddError("Phone number is empty");
            }
            else if (!PhoneNumberIsFormattedCorrectly(bidder.Phone))
            {
                val.AddError("Phone number is not in the correct format");
            }

            if (!_eventRepo.EventExists(bidder.EventId, ref trans))
            {
                val.AddError("Must be in valid auction");
            }
            else
            {
                if (bidder.Id > 0)
                {
                    var bidderInSystem = _bidderRepo.GetByNumberAndEvent(bidder.Number,
                                                                         bidder.EventId,
                                                                         ref trans);

                    if (bidderInSystem.Id != bidder.Id)
                    {
                        val.AddError("Invalid bidder number");
                    }
                }
            }

            return val;
        }
        public IList<Auction.Domain.Donor> GetByEvent(long eventId,
                                ref IAuctionTransaction trans)
        {
            using (var donors = new DonorCollection())
            {
                var relations = new RelationCollection {AuctionEventDonorEntity.Relations.DonorEntityUsingDonorId};
                var filter = new PredicateExpression { AuctionEventDonorFields.EventId == eventId };
                donors.GetMulti(filter, relations);

                return donors.Select(d => new Donor()
                {
                    Id = d.Id,
                    AccountId = d.AccountId,
                    Name = d.Name,
                    Notes = d.Notes,
                    Phone = d.Phone
                }).ToList();
            }
        }
        public Validation ValidateExistingEvent(Event auctionEvent, ref IAuctionTransaction trans)
        {
            var val = new Validation();

            if (auctionEvent.Id <= 0)
            {
                val.AddError("Auction must have an id");
            }
            if (auctionEvent.Name == string.Empty)
            {
                val.AddError("Name is empty");
            }

            if (auctionEvent.Date == DateTime.MinValue)
            {
                val.AddError("Date is not set");
            }

            return val;
        }
        public Validation ValidateNewEvent(Event auctionEvent, ref IAuctionTransaction trans)
        {
            var val = new Validation();

            if (String.IsNullOrEmpty(auctionEvent.Name))
            {
                val.AddError("Name is empty");
            }

            if(auctionEvent.Date == DateTime.MinValue)
            {
                val.AddError("Date is not set");
            }

            int accountLimit = _accountRepo.GetAllowableEventCount(auctionEvent.AccountId, ref trans);
            int currentEventCount = _eventRepo.GetCountByAccount(auctionEvent.AccountId, ref trans);

            if(currentEventCount + 1 > accountLimit)
            {
                val.AddError("Account has reached maximum number of licensed events");
            }

            return val;
        }
 public void Update(ref Auction.Domain.Item item,
                    ref IAuctionTransaction trans)
 {
     //throw new NotImplementedException();
 }