public Validation ValidateNewDonor(Donor donor)
        {
            IAuctionTransaction trans = null;

            var val = new Validation();

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

            if (string.IsNullOrEmpty(donor.Address))
            {
                val.AddError("Address is empty");
            }

            if (string.IsNullOrEmpty(donor.Phone))
            {
                val.AddError("Phone is empty");
            }

            if (donor.AccountId == 0)
            {
                val.AddError("Account is not set");
            }
            else if (_accountRepo.AccountExists(donor.AccountId, ref trans))
            {
                val.AddError("Not set to a valid Account");
            }

            return val;
        }
        public Validation DeleteDonor(long donorId)
        {
            IAuctionTransaction trans = _factory.BuildTransaction("DeleteDonor");

            var val = new Validation();
            try
            {
                if (!_validator.CanDonorBeDeleted(donorId, ref trans))
                {
                    val.AddError("Donor cannot be deleted");
                }
                else
                {
                    _repo.RemoveFromAllEvents(donorId, ref trans);
                    _repo.Delete(donorId, ref trans);
                }
                trans.Commit();
            }
            catch (Exception ex)
            {
                trans.Rollback();
                val.AddError(string.Format("Unable to delete Donor: {0}", ex.Message));
            }
            finally
            {
                trans.Dispose();
            }

            return val;
        }
        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 Validation AddDonorToEvent(long donorId,
                                   long eventId)
 {
     var val = new Validation();
     //verify that they are not already in event
     var trans = _factory.BuildTransaction("AddDonorToEvent");
     try
     {
         if (_eventRepo.GetEventListByDonor(donorId, ref trans).Contains(eventId))
         {
             throw new ApplicationException("Donor is already associated with the event");
         }
         _repo.AddToEvent(donorId, eventId, ref trans);
         trans.Commit();
     }
     catch (Exception e)
     {
         trans.Rollback();
         val.AddError(string.Format("Unable to add donor to event: {0}", e.Message));
     }
     finally
     {
         trans.Dispose();
     }
     return val;
 }
        public Validation CheckoutBidder(long eventId, int number, long userId)
        {
            var val = new Validation();
            IAuctionTransaction trans = _factory.BuildTransaction("CheckoutBidder");

            try
            {
                var bidder = _bidderRepo.GetByNumberAndEvent(number, eventId, ref trans);
                var packages = _packageRepo.GetByBidder(bidder.Id, ref trans).Where(p => !p.Paid);

                if(packages.Count() == 0)
                {
                    throw new ApplicationException("No packages to checkout");
                }
                packages.ToList().ForEach(p => { p.Paid = true; _packageRepo.Update(ref p, ref trans); });

                bidder.CheckedoutBy = userId;
                _bidderRepo.Update(ref bidder, ref trans);
                trans.Commit();
            }
            catch (Exception ex)
            {
                trans.Rollback();
                val.AddError(string.Format("Unable to checkout bidder: {0}", ex.Message));
            }
            finally
            {
                trans.Dispose();
            }

            return val;
        }
Exemplo n.º 6
0
        public Validation DeletePackage(long packageId)
        {
            var val = new Validation();
            IAuctionTransaction trans = null;
            var package = _repo.Get(packageId, ref trans);
            if(package.Paid)
            {
                val.AddError("Package is already checked out");
            }
            else if(package.BidderId > 0)
            {
                val.AddError("Package is already closed out");
            }

            return val;
        }
        public Validation DeleteCategory(long categoryId)
        {
            var val = new Validation();
            IAuctionTransaction trans = _factory.BuildTransaction("DeleteCategory");

            try
            {
                if (_packageRepo.GetByCategory(categoryId, ref trans).Count > 0)
                {
                    throw new ApplicationException("Category is associated with packages");
                }
                _repo.Delete(categoryId, ref trans);

                trans.Commit();
            }
            catch (Exception e)
            {
                trans.Rollback();
                val.AddError(string.Format("Unable to delete category: {0}", e.Message));
            }
            finally
            {
                trans.Dispose();
            }
            return val;
        }
Exemplo n.º 8
0
        public Validation CreateEvent(ref Event auctionEvent,
                                      long currentUserId)
        {
            var val = new Validation();

            var trans = _factory.BuildTransaction("CreateEvent");

            try
            {
                val = _validator.ValidateNewEvent(auctionEvent, ref trans);
                if (val.IsValid)
                {
                    auctionEvent.CreatedBy = currentUserId;
                    _repo.Insert(ref auctionEvent, ref trans);
                }
                trans.Commit();
            }
            catch (Exception e)
            {
                trans.Rollback();
                val.AddError(string.Format("Unable to create auction: {0}", e.Message));
            }
            finally
            {
                trans.Dispose();
            }

            return val;
        }
Exemplo n.º 9
0
 public Validation DeleteUser(long userId)
 {
     //why would we not want to delete a user?
     //we cannot delete a user if they are the account admin
     var trans = _factory.BuildTransaction("DeleteUser");
     var val = new Validation();
     try
     {
         var user = _repo.Get(userId, ref trans);
         if (_accountRepo.GetMainUserId(user.AccountId, ref trans) == userId)
         {
             throw new ApplicationException("User is account admin");
         }
         _repo.DeleteUser(userId, ref trans);
         trans.Commit();
     }
     catch (Exception e)
     {
         trans.Rollback();
         val.AddError(string.Format("Unable to create user: {0}", e.Message));
     }
     finally
     {
         trans.Dispose();
     }
     return val;
 }
Exemplo n.º 10
0
        public Validation CreateBidder(ref Bidder eventBidder,
                                       long currentUserId)
        {
            var val = new Validation();

            var trans = _factory.BuildTransaction("CreateBidder");

            try
            {
                val = _validator.ValidateNewBidder(eventBidder, ref trans);
                if(val.IsValid)
                {
                    eventBidder.Number = _repo.GetByEvent(eventBidder.EventId, ref trans).Select(b => b.Number).Max() + 1;
                    eventBidder.CreatedBy = currentUserId;
                    _repo.Insert(ref eventBidder, ref trans);
                }
                trans.Commit();
            }
            catch(Exception e)
            {
                trans.Rollback();
                val.AddError(string.Format("Unable to create bidder: {0}", e.Message));
            }
            finally
            {
                trans.Dispose();
            }

            return val;
        }
Exemplo n.º 11
0
 public Validation DeleteItem(long itemId)
 {
     //we do not want to delete an item if it is in a package
     var trans = _factory.BuildTransaction("DeleteItem");
     var val = new Validation();
     try
     {
         var item = _repo.Get(itemId, ref trans);
         if (item.PackageId.HasValue)
         {
             throw new ApplicationException("Item is in a package");
         }
         _repo.Delete(itemId, ref trans);
         trans.Commit();
     }
     catch (Exception e)
     {
         trans.Rollback();
         val.AddError(string.Format("Unable to delete item: {0}", e.Message));
     }
     finally
     {
         trans.Dispose();
     }
     return val;
 }
Exemplo n.º 12
0
        public Validation CreateItem(ref Item item)
        {
            var val = new Validation();

            var trans = _factory.BuildTransaction("InsertItem");
            try
            {
                //validate
                if (val.IsValid)
                {
                    _repo.Insert(ref item, ref trans);
                }
                trans.Commit();
            }
            catch (Exception e)
            {
                trans.Rollback();
                val.AddError(string.Format("Unable to create item: {0}", e.Message));
            }
            finally
            {
                trans.Dispose();
            }
            return val;
        }
        public Validation DeleteBidder(long eventId, int number)
        {
            //we need to check that they do not have any closedout/checkedout packages
            //we can delete only if they do not
            var val = new Validation();

            var trans = _factory.BuildTransaction("DeleteBidder");

            try
            {
                var bidder = _repo.GetByNumberAndEvent(number, eventId, ref trans);

                if (_packageRepo.GetByBidder(bidder.Id, ref trans).Count > 0)
                {
                    throw new ApplicationException("Bidder is associated with packages");
                }
                _repo.Delete(bidder.Id, ref trans);
                trans.Commit();
            }
            catch (Exception e)
            {
                trans.Rollback();
                val.AddError(string.Format("Unable to delete bidder: {0}", e.Message));
            }
            finally
            {
                trans.Dispose();
            }
            return val;
        }
        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;
        }
Exemplo n.º 16
0
 public Validation DeleteRaffle(long raffleId)
 {
     var val = new Validation();
     var trans = _factory.BuildTransaction("DeleteRaffle");
     try
     {
         _repo.DeleteRaffle(raffleId, ref trans);
         trans.Commit();
     }
     catch (Exception ex)
     {
         trans.Rollback();
         val.AddError(string.Format("Unable to delete raffle: {0}", ex.Message));
     }
     finally
     {
         trans.Dispose();
     }
     return val;
 }
Exemplo n.º 17
0
 public Validation DeleteExpense(long expenseId)
 {
     IAuctionTransaction trans = _factory.BuildTransaction("DeleteExpense");
     var val = new Validation();
     try
     {
         _repo.DeleteExpense(expenseId, ref trans);
         trans.Commit();
     }
     catch (Exception e)
     {
         trans.Rollback();
         val.AddError(string.Format("Unable to delete expense: {0}", e.Message));
     }
     finally
     {
         trans.Dispose();
     }
     return val;
 }
        public Validation CloseoutPackage(string packageCode, int bidderNumber, double endBid, long eventId, long userId)
        {
            var val = new Validation();

            IAuctionTransaction trans = _factory.BuildTransaction("CloseoutPackage");
            try
            {
                var package = _packageRepo.GetByEvent(eventId, ref trans).ToList()
                             .Where(p => p.Code == packageCode).First();

                if(package.Paid)
                {
                    throw new ApplicationException("Package is already processed and paid for");
                }

                long bidderId = _bidderRepo.GetByNumberAndEvent(bidderNumber, eventId, ref trans).Id;

                package.BidderId = (int?)bidderId;
                package.EndingBid = (decimal?) endBid;
                package.ClosedOutBy = userId;

                _packageRepo.Update(ref package, ref trans);

                trans.Commit();
            }
            catch (Exception e)
            {
                trans.Rollback();
                val.AddError(string.Format("Unable to closeout package: {0}", e.Message));
            }
            finally
            {
                trans.Dispose();
            }

            return val;
        }
        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 Validation RemoveDonorFromEvent(long donorId,
                                        long eventId)
 {
     var val = new Validation();
     //verify that they are not already in event
     var trans = _factory.BuildTransaction("RemoveDonorFromEvent");
     try
     {
         if (_itemRepo.GetByDonorAndEvent(donorId, eventId, ref trans).Count > 0)
         {
             throw new ApplicationException("Event items are associated with the donor");
         }
         _repo.RemoveFromEvent(donorId, eventId, ref trans);
         trans.Commit();
     }
     catch (Exception e)
     {
         trans.Rollback();
         val.AddError(string.Format("Unable to add donor to event: {0}", e.Message));
     }
     finally
     {
         trans.Dispose();
     }
     return val;
 }
Exemplo n.º 21
0
        public Validation UpdateBidder(ref Bidder eventBidder)
        {
            var val = new Validation();

            var trans = _factory.BuildTransaction("UpdateBidder");

            try
            {
                val = _validator.ValidateExistingBidder(eventBidder, ref trans);
                if(val.IsValid)
                {
                    _repo.Update(ref eventBidder, ref trans);
                }
                trans.Commit();
            }
            catch(Exception e)
            {
                trans.Rollback();
                val.AddError(string.Format("Unable to update bidder: {0}", e.Message));
            }
            finally
            {
                trans.Dispose();
            }

            return val;
        }
Exemplo n.º 22
0
        private static Validation Validate(Expense expense)
        {
            var val = new Validation();
            if (string.IsNullOrEmpty(expense.Name))
            {
                val.AddError("Name is required");
            }

            if (expense.EventId < 0)
            {
                val.AddError("Event is required");
            }
            return val;
        }
Exemplo n.º 23
0
        public Validation UpdateUser(ref User user)
        {
            var val = new Validation();

            var trans = _factory.BuildTransaction("UpdateUser");
            try
            {
                //validate
                if (val.IsValid)
                {
                    _repo.Update(ref user, ref trans);
                }
                trans.Commit();
            }
            catch (Exception e)
            {
                trans.Rollback();
                val.AddError(string.Format("Unable to update user: {0}", e.Message));
            }
            finally
            {
                trans.Dispose();
            }
            return val;
        }
Exemplo n.º 24
0
        private static Validation Validate(Domain.Raffle raffle)
        {
            var val = new Validation();
            if (string.IsNullOrEmpty(raffle.Name))
            {
                val.AddError("Name is required");
            }

            if (raffle.EventId < 0)
            {
                val.AddError("Event is required");
            }
            return val;
        }