Example #1
0
        public static List <OrderManageView> GetAllOrdersManageView(ApplicationDbContext db, IPrincipal user, bool getHistory)
        {
            List <OrderManageView> allOrdersManageView = new List <OrderManageView>();

            AppUser      appUser          = AppUserHelpers.GetAppUser(db, user);
            List <Order> allOrdersForUser = OrderHelpers.GetAllManageListingFilteredOrders(db, appUser.AppUserId, getHistory);

            //If we allow branch trading then differentiate between branches for in/out trading, otherwise it is at company level
            Company company = CompanyHelpers.GetCompanyForUser(db, user);

            foreach (Order orderForBranchUser in allOrdersForUser)
            {
                OrderManageView orderManageView = new OrderManageView();
                orderManageView.OrderDetails = orderForBranchUser;

                //set Inhouse flag
                orderManageView.InhouseOrder = OrderProcessHelpers.SetInhouseFlag(orderForBranchUser, appUser, company);

                //Set OrderOut flag
                orderManageView.OrderOut = OrderProcessHelpers.SetOrderOutFlag(orderForBranchUser, orderManageView.InhouseOrder);

                //set buttons
                bool?displayDespatchButton  = null;
                bool?displayDeliveredButton = null;
                bool?displayReceivedButton  = null;
                bool?displayCollectedButton = null;
                bool?displayClosedButton    = null;

                OrderProcessHelpers.SetOrderButtons(db, user, orderForBranchUser, orderManageView.OrderOut, out displayDespatchButton, out displayDeliveredButton, out displayReceivedButton, out displayCollectedButton, out displayClosedButton);

                orderManageView.DisplayDespatchButton  = displayDespatchButton;
                orderManageView.DisplayDeliveredButton = displayDeliveredButton;
                orderManageView.DisplayReceivedButton  = displayReceivedButton;
                orderManageView.DisplayCollectedButton = displayCollectedButton;
                orderManageView.DisplayClosedButton    = displayClosedButton;

                allOrdersManageView.Add(orderManageView);
            }

            return(allOrdersManageView);
        }
Example #2
0
        public static OrderEditView GetOrderEditView(ApplicationDbContext db, Guid orderId, IPrincipal user)
        {
            Order              orderDetails       = OrderHelpers.GetOrder(db, orderId);
            AppUser            orderAppUser       = null;
            Branch             orderBranch        = null;
            AppUser            offerAppUser       = null;
            Branch             offerBranch        = null;
            AppUser            listingAppUser     = null;
            Branch             listingBranch      = null;
            Offer              offerDetails       = null;
            AvailableListing   availableListing   = null;
            RequirementListing requirementListing = null;

            if (orderDetails.OrderOriginatorAppUserId != null)
            {
                if (orderDetails.OrderOriginatorAppUserId.Value != Guid.Empty)
                {
                    orderAppUser = AppUserHelpers.GetAppUser(db, orderDetails.OrderOriginatorAppUserId.Value);
                }
            }

            if (orderDetails.OrderOriginatorBranchId != null)
            {
                if (orderDetails.OrderOriginatorBranchId.Value != Guid.Empty)
                {
                    orderBranch = BranchHelpers.GetBranch(db, orderDetails.ListingOriginatorBranchId.Value);
                }
            }

            if (orderDetails.OfferOriginatorAppUserId != null)
            {
                if (orderDetails.OfferOriginatorAppUserId.Value != Guid.Empty)
                {
                    offerAppUser = AppUserHelpers.GetAppUser(db, orderDetails.OfferOriginatorAppUserId.Value);
                }
            }

            if (orderDetails.OfferOriginatorBranchId != null)
            {
                if (orderDetails.OfferOriginatorBranchId.Value != Guid.Empty)
                {
                    offerBranch = BranchHelpers.GetBranch(db, orderDetails.OfferOriginatorBranchId.Value);
                }
            }

            if (orderDetails.ListingOriginatorAppUserId != null)
            {
                if (orderDetails.ListingOriginatorAppUserId.Value != Guid.Empty)
                {
                    listingAppUser = AppUserHelpers.GetAppUser(db, orderDetails.ListingOriginatorAppUserId.Value);
                }
            }

            if (orderDetails.ListingOriginatorBranchId != null)
            {
                if (orderDetails.ListingOriginatorBranchId.Value != Guid.Empty)
                {
                    listingBranch = BranchHelpers.GetBranch(db, orderDetails.ListingOriginatorBranchId.Value);
                }
            }

            if (orderDetails.OfferId != null)
            {
                if (orderDetails.OfferId.Value != Guid.Empty)
                {
                    offerDetails = OfferHelpers.GetOffer(db, orderDetails.OfferId.Value);
                    if (orderDetails.ListingId != null)
                    {
                        if (orderDetails.ListingId.Value != Guid.Empty)
                        {
                            switch (offerDetails.ListingType)
                            {
                            case ListingTypeEnum.Available:
                                availableListing = AvailableListingHelpers.GetAvailableListing(db, orderDetails.ListingId.Value);
                                break;

                            case ListingTypeEnum.Requirement:
                                requirementListing = RequirementListingHelpers.GetRequirementListing(db, orderDetails.ListingId.Value);
                                break;
                            }
                        }
                    }
                }
            }

            OrderEditView view = new OrderEditView()
            {
                OrderId                   = orderDetails.OrderId,
                ListingType               = orderDetails.ListingType,
                OrderQuanity              = orderDetails.OrderQuanity,
                OrderStatus               = orderDetails.OrderStatus,
                OrderCreationDateTime     = orderDetails.OrderCreationDateTime,
                OrderDistributionDateTime = orderDetails.OrderDistributionDateTime,
                OrderDeliveredDateTime    = orderDetails.OrderDeliveredDateTime,
                OrderCollectedDateTime    = orderDetails.OrderCollectedDateTime,
                OrderClosedDateTime       = orderDetails.OrderClosedDateTime,
                OrderAppUser              = orderAppUser,
                OrderBranchDetails        = orderBranch,
                OfferId                   = orderDetails.OfferId.GetValueOrDefault(),
                OfferAppUser              = offerAppUser,
                OfferBranchDetails        = offerBranch,
                OfferDetails              = offerDetails,
                ListingId                 = orderDetails.ListingId.GetValueOrDefault(),
                ListingAppUser            = listingAppUser,
                ListingBranchDetails      = listingBranch,
                AvailableListingDetails   = availableListing,
                RequirementListingDetails = requirementListing
            };

            AppUser thisAppUser = AppUserHelpers.GetAppUser(db, user);
            //If we allow branch trading then differentiate between branches for in/out trading, otherwise it is at company level
            Company thisCompany = CompanyHelpers.GetCompanyForUser(db, user);

            //set Inhouse flag
            view.InhouseOrder = OrderProcessHelpers.SetInhouseFlag(orderDetails, thisAppUser, thisCompany);

            //Set OrderOut flag
            view.OrderOut = OrderProcessHelpers.SetOrderOutFlag(orderDetails, view.InhouseOrder);

            //set buttons
            bool?displayDespatchButton  = null;
            bool?displayDeliveredButton = null;
            bool?displayReceivedButton  = null;
            bool?displayCollectedButton = null;
            bool?displayClosedButton    = null;

            OrderProcessHelpers.SetOrderButtons(db, user, orderDetails, view.OrderOut, out displayDespatchButton, out displayDeliveredButton, out displayReceivedButton, out displayCollectedButton, out displayClosedButton);

            view.DisplayDespatchButton  = displayDespatchButton;
            view.DisplayDeliveredButton = displayDeliveredButton;
            view.DisplayReceivedButton  = displayReceivedButton;
            view.DisplayCollectedButton = displayCollectedButton;
            view.DisplayClosedButton    = displayClosedButton;

            return(view);
        }