コード例 #1
0
        //private decimal getAllOrder_InMoney_For(BuySellDocStateENUM buySellDocStateEnum, BuySellDocumentTypeENUM buySellDocumentTypeEnum, string userId, DateTime fromDate, DateTime toDate)
        //{

        //    //get all purchase orders for Owner
        //    List<BuySellDoc> purchaseOrdersLst = getAllPurchaseOrders_For(userId, buySellDocStateEnum);

        //    //add up the purchase amoung
        //    if (purchaseOrdersLst.IsNullOrEmpty())
        //        return 0;

        //    decimal totalPurchase = 0;
        //    foreach (var item in purchaseOrdersLst)
        //    {
        //        totalPurchase += item.TotalRemaining;
        //    }

        //    return totalPurchase;
        //}

        //private List<BuySellDoc> getAllDocuments_For(string userId, BuySellDocStateENUM buySellDocStateEnum)
        //{
        //    List<BuySellDoc> purchaseOrdersLst = new List<BuySellDoc>();
        //    switch (buySellDocStateEnum)
        //    {
        //        case BuySellDocStateENUM.New:
        //        case BuySellDocStateENUM.InProccess:
        //        case BuySellDocStateENUM.Closed:
        //        case BuySellDocStateENUM.BackOrdered:
        //        case BuySellDocStateENUM.Canceled:
        //        case BuySellDocStateENUM.Quotation:
        //        case BuySellDocStateENUM.Credit:
        //            purchaseOrdersLst = getAllPurchaseOrders_For(userId)
        //               .Where(x => x.BuySellDocStateEnum == buySellDocStateEnum)
        //               .ToList();
        //            break;
        //        case BuySellDocStateENUM.All:
        //            purchaseOrdersLst = getAllPurchaseOrders_For(userId)
        //               .Where(x =>
        //                   x.BuySellDocStateEnum == BuySellDocStateENUM.New ||
        //                   x.BuySellDocStateEnum == BuySellDocStateENUM.InProccess)
        //               .ToList();
        //            break;
        //        case BuySellDocStateENUM.Unknown:
        //        default:
        //            throw new Exception("State of document is unknown.");
        //    }
        //    //get all purchase orders for Owner
        //    return purchaseOrdersLst;
        //}



        #region General Methods



        private Customer getCustomerFor(string userId)
        {
            Customer customer = CustomerBiz.GetPlayerFor(userId);

            customer.IsNullThrowException("customer");
            return(customer);
        }
コード例 #2
0
        private IQueryable <BuySellDoc> getAllPurchaseOrders_For(string userId)
        {
            //we need to be able to get all the purchase orders here without the userid
            //userId.IsNullOrWhiteSpaceThrowArgumentException("You are not logged in.");


            //when selling, the user is the owner
            IQueryable <BuySellDoc> purchaseOrdersIq = FindAll();

            if (userId.IsNullOrWhiteSpace())
            {
                return(purchaseOrdersIq);
            }
            Customer customer;

            try
            {
                customer = CustomerBiz.GetPlayerFor(userId);
                customer.IsNullThrowException("Customer");
            }
            catch (Exception e)
            {
                ErrorsGlobal.Add("No Owner is attached", MethodBase.GetCurrentMethod(), e);
                throw new Exception(ErrorsGlobal.ToString());
            }


            //get all purchase orders for Owner
            purchaseOrdersIq = purchaseOrdersIq
                               .Where(x => x.CustomerId == customer.Id);

            return(purchaseOrdersIq);
        }
コード例 #3
0
ファイル: Shop.cs プロジェクト: dovanduy/Library
        private Customer getCustomerOfUser()
        {
            Customer customerUser = CustomerBiz.GetPlayerFor(UserId);

            customerUser.IsNullThrowException("Unable to get customer for user.");
            return(customerUser);
        }
コード例 #4
0
ファイル: Index.cs プロジェクト: dovanduy/Library
        public override async Task <IList <ICommonWithId> > GetListForIndexAsync(ControllerIndexParams parms)
        {
            //get user's customer and owner
            Customer customer = CustomerBiz.GetPlayerFor(UserId);
            Owner    owner    = OwnerBiz.GetPlayerFor(UserId);


            //now, get all the payment trx for this person
            List <BuySellDoc> allTrx = await FindAllAsync();

            List <BuySellDoc> filteredTrx;

            //now reduce this list so the user is customer or seller
            if (customer.IsNull())
            {
                if (owner.IsNull())
                {
                    //filteredTrx = allTrx.Where(x => x.CustomerId == customerId).AsQueryable();
                    return(null);
                }
                else
                {
                    filteredTrx = allTrx.Where(x => x.OwnerId == owner.Id).ToList();
                }
            }
            else
            {
                if (owner.IsNull())
                {
                    filteredTrx = allTrx.Where(x => x.CustomerId == customer.Id).ToList();
                }
                else
                {
                    filteredTrx = allTrx.Where(x => x.CustomerId == customer.Id || x.OwnerId == owner.Id).ToList();
                }
            }

            //cast and return the list
            var lstIcommonwithId = allTrx.Cast <ICommonWithId>().ToList();

            return(lstIcommonwithId);
        }
コード例 #5
0
        public string AddToSale(string userId, string productChildId, string poNumber, DateTime poDate)
        {
            userId.IsNullOrWhiteSpaceThrowException("No user");

            double totalThisItem = 0;

            //who is the owner:The product Child owner is the owner
            //get the productChild

            productChildId.IsNullOrWhiteSpaceThrowException("No Product");
            ProductChild productChild = ProductChildBiz.Find(productChildId);

            productChild.IsNullThrowException("productChild");



            //get the product child's owner
            Owner ownerProductChild = productChild.Owner;

            ownerProductChild.IsNullThrowException("productChildOwner");

            //get the owner
            //Get the select list for owner
            Person ownerPerson = ownerProductChild.Person;

            ownerPerson.IsNullThrowException("ownerPerson");
            System.Web.Mvc.SelectList ownerSelectList = OwnerBiz.SelectListOnlyWith(ownerProductChild);


            ////the user is the customer user;
            //get the customer
            Customer customerUser = CustomerBiz.GetPlayerFor(userId);

            //Get the select list for Customer
            //remove the owner from the list... owner cannot sell to self.
            System.Web.Mvc.SelectList customerSelectList = CustomerBiz.SelectListWithout(ownerPerson);
            System.Web.Mvc.SelectList selectListOwner    = OwnerBiz.SelectListOnlyWith(ownerProductChild);
            System.Web.Mvc.SelectList selectListCustomer = CustomerBiz.SelectListWithout(ownerPerson);

            //this is the address in the customer
            AddressMain    addressBillTo          = customerUser.DefaultBillAddress;
            AddressMain    addressShipTo          = customerUser.DefaultShipAddress;
            AddressComplex addressShipFromComplex = productChild.ShipFromAddressComplex;

            string addressBillToId = "";
            string addressShipToId = "";

            if (!addressBillTo.IsNull())
            {
                addressBillToId = addressBillTo.Id;
            }

            if (!addressShipTo.IsNull())
            {
                addressShipToId = addressShipTo.Id;
            }


            //Get the select list for AddressInform
            System.Web.Mvc.SelectList selectListBillTo = AddressBiz.SelectListBillAddressCurrentUser();
            //Get the select list for AddressShipTo
            System.Web.Mvc.SelectList selectListShipTo = AddressBiz.SelectListShipAddressCurrentuser();



            //check to see if there is any open sale which belongs to the same buyer and seller
            BuySellDoc sale = BuySellDocBiz.GetOpenSaleWithSameCustomerAndSeller(customerUser.Id, ownerProductChild.Id, productChild);

            //create the itemList.
            List <BuySellItem> buySellItems = new List <BuySellItem>();
            string             shopId       = "";

            if (sale.IsNull())
            {
                //otherwise add a new sale
                sale = CreateSale(
                    productChild,
                    ownerProductChild,
                    1,
                    productChild.Sell.SellPrice,
                    customerUser,
                    selectListOwner,
                    selectListCustomer,
                    addressBillToId,
                    addressShipToId,
                    selectListBillTo,
                    selectListShipTo,
                    BuySellDocStateENUM.RequestUnconfirmed,
                    BuySellDocStateModifierENUM.Unknown,
                    DateTime.Now,
                    DateTime.Now,
                    shopId);

                totalThisItem++;
            }

            else
            {
                //dont really need this, but it is good for consistancy.
                sale.BuySellDocumentTypeEnum = BuySellDocumentTypeENUM.Purchase;
                sale.BuySellDocStateEnum     = BuySellDocStateENUM.RequestUnconfirmed;

                //now check to see if it is the same item... or is it a new item
                //get list of items for the sale
                List <BuySellItem> itemList = sale.BuySellItems.Where(x => x.MetaData.IsDeleted == false).ToList();

                if (itemList.IsNullOrEmpty())
                {
                    BuySellItem buySellItem = new BuySellItem(sale.Id, productChild.Id, 1, productChild.Sell.SellPrice, productChild.FullName());
                    sale.Add(buySellItem);
                }
                else
                {
                    //there are items in the list
                    BuySellItem itemFound = itemList.FirstOrDefault(x => x.ProductChildId == productChild.Id);
                    if (itemFound.IsNull())
                    {
                        BuySellItem buySellItem = new BuySellItem(sale.Id, productChild.Id, 1, productChild.Sell.SellPrice, productChild.FullName());
                        sale.Add(buySellItem);
                    }
                    else
                    {
                        totalThisItem                     = itemFound.Quantity.Order;
                        itemFound.Quantity.Order         += 1;
                        itemFound.Quantity.Order_Original = itemFound.Quantity.Order;
                        //itemFound.Quantity.Ship += 1;
                    }
                }

                totalThisItem++;
                sale.AddressShipFromComplex = addressShipFromComplex;

                BuySellDocBiz.GetDefaultVehicalType(sale);
                sale.AddressShipFromId = productChild.ShipFromAddressId;

                sale.RequestUnconfirmed.SetToTodaysDate(UserName, UserId);

                ControllerCreateEditParameter parm = new ControllerCreateEditParameter();
                parm.Entity       = sale as ICommonWithId;
                parm.GlobalObject = GetGlobalObject();

                BuySellDocBiz.Update(parm);
            }

            BuySellDocBiz.SaveChanges();
            string message = string.Format("Success. You ordered {0:N2} for {1:N2} (X{2:N2})", productChild.FullName(), productChild.Sell.SellPrice, totalThisItem);

            return(message);
        }
コード例 #6
0
        IQueryable <BuySellDoc> getByDocumentType_For(string userId, IQueryable <BuySellDoc> iq_allOrders, BuySellDocumentTypeENUM buySellDocumentTypeEnum)
        {
            //userId.IsNullOrWhiteSpaceThrowArgumentException("You are not logged in.");


            switch (buySellDocumentTypeEnum)
            {
            case BuySellDocumentTypeENUM.Sale:
            {
                try
                {
                    //all orders are returned because this is the admin
                    //if (userId.IsNullOrWhiteSpace())
                    //    return iq_allOrders;
                    if (userId.IsNullOrWhiteSpace())
                    {
                        return(BuySellDoc.IQueryable_GetSaleDocs(iq_allOrders, ""));
                    }

                    Owner owner = OwnerBiz.GetPlayerFor(userId);
                    owner.IsNullThrowException("No Owner");
                    return(BuySellDoc.IQueryable_GetSaleDocs(iq_allOrders, owner.Id));
                }
                catch (Exception e)
                {
                    ErrorsGlobal.Add("Problem getting sales.", MethodBase.GetCurrentMethod(), e);
                    throw new Exception(ErrorsGlobal.ToString());
                }
            }

            case BuySellDocumentTypeENUM.Purchase:
            {
                try
                {
                    //all orders are returned because this is the admin
                    //if (userId.IsNullOrWhiteSpace())
                    //    return iq_allOrders;
                    if (userId.IsNullOrWhiteSpace())
                    {
                        return(BuySellDoc.IQueryable_GetPurchaseDocs(iq_allOrders, ""));
                    }

                    Customer customer = CustomerBiz.GetPlayerFor(userId);
                    customer.IsNullThrowException("Customer");
                    return(BuySellDoc.IQueryable_GetPurchaseDocs(iq_allOrders, customer.Id));
                }
                catch (Exception e)
                {
                    ErrorsGlobal.Add("Problem getting purchases", MethodBase.GetCurrentMethod(), e);
                    throw new Exception(ErrorsGlobal.ToString());
                }
            }

            case BuySellDocumentTypeENUM.Delivery:
            {
                try
                {
                    //all orders are returned because this is the admin
                    if (userId.IsNullOrWhiteSpace())
                    {
                        return(BuySellDoc.IQueryable_GetDeliveryDocs(iq_allOrders, ""));
                    }


                    Deliveryman deliveryMan = DeliverymanBiz.GetPlayerFor(userId);
                    deliveryMan.IsNullThrowException("deliveryMan");

                    return(BuySellDoc.IQueryable_GetDeliveryDocs(iq_allOrders, deliveryMan.Id));
                }
                catch (Exception e)
                {
                    ErrorsGlobal.Add("Problem getting purchases", MethodBase.GetCurrentMethod(), e);
                    throw new Exception(ErrorsGlobal.ToString());
                }
            }

            case BuySellDocumentTypeENUM.Salesman:
            {
                try
                {
                    if (userId.IsNullOrWhiteSpace())
                    {
                        return(BuySellDoc.IQueryable_GetSalesmanDocs(iq_allOrders, ""));
                    }

                    Salesman salesman = SalesmanBiz.GetPlayerFor(userId);
                    salesman.IsNullThrowException("Salesman");

                    return(BuySellDoc.IQueryable_GetSalesmanDocs(iq_allOrders, salesman.Id));
                }
                catch (Exception e)
                {
                    ErrorsGlobal.Add("Problem getting purchases", MethodBase.GetCurrentMethod(), e);
                    throw new Exception(ErrorsGlobal.ToString());
                }
            }

            case BuySellDocumentTypeENUM.Unknown:
            default:
                throw new Exception("Unknown document type");
            }
        }