public static AvailableListing UpdateAvailableListingQuantities(ApplicationDbContext db, Guid listingId, ListingQuantityChange changeOfValue, decimal changeQty, IPrincipal user)
        {
            AvailableListing listing = AvailableListingHelpers.GetAvailableListing(db, listingId);

            listing.RecordChange   = RecordChangeEnum.RecordUpdated;
            listing.RecordChangeBy = AppUserHelpers.GetAppUserIdFromUser(user);
            listing.RecordChangeOn = DateTime.Now;

            if (changeOfValue == ListingQuantityChange.Subtract)
            {
                listing.QuantityFulfilled   += changeQty;
                listing.QuantityOutstanding -= changeQty;

                if (listing.QuantityOutstanding == 0)
                {
                    listing.ListingStatus = ItemRequiredListingStatusEnum.Complete;
                    listing.RecordChange  = RecordChangeEnum.ListingStatusChange;
                }
            }
            else
            {
                listing.QuantityFulfilled   -= changeQty;
                listing.QuantityOutstanding += changeQty;
            }

            db.Entry(listing).State = EntityState.Modified;
            db.SaveChanges();

            return(listing);
        }
예제 #2
0
        public static Offer CreateOffer(ApplicationDbContext db, Guid listingId, decimal?offerQty, ListingTypeEnum listingType, AppUser currentUser, IPrincipal user)
        {
            if (currentUser == null)
            {
                currentUser = AppUserHelpers.GetAppUser(db, user);
            }

            Guid     listingOrigAppUserId = Guid.Empty;
            Guid     listingOrigOrgId     = Guid.Empty;
            DateTime listingOrigDateTime  = DateTime.MinValue;
            string   itemDescription      = "";

            //Get originator information for the correct listing
            if (listingType == ListingTypeEnum.Available)
            {
                AvailableListing availableListing = AvailableListingHelpers.GetAvailableListing(db, listingId);
                listingOrigAppUserId = availableListing.ListingOriginatorAppUserId;
                listingOrigOrgId     = availableListing.ListingOriginatorOrganisationId;
                listingOrigDateTime  = availableListing.ListingOriginatorDateTime;
                itemDescription      = availableListing.ItemDescription;
            }
            else
            {
                RequiredListing requiredListing = RequiredListingHelpers.GetRequiredListing(db, listingId);
                listingOrigAppUserId = requiredListing.ListingOriginatorAppUserId;
                listingOrigOrgId     = requiredListing.ListingOriginatorOrganisationId;
                listingOrigDateTime  = requiredListing.ListingOriginatorDateTime;
                itemDescription      = requiredListing.ItemDescription;
            }

            //create offer
            Offer offer = new Offer()
            {
                OfferId                         = Guid.NewGuid(),
                ListingId                       = listingId,
                ListingType                     = listingType,
                OfferStatus                     = OfferStatusEnum.New,
                ItemDescription                 = itemDescription,
                CurrentOfferQuantity            = offerQty.Value,
                OfferOriginatorAppUserId        = currentUser.AppUserId,
                OfferOriginatorOrganisationId   = currentUser.OrganisationId,
                OfferOriginatorDateTime         = DateTime.Now,
                ListingOriginatorAppUserId      = listingOrigAppUserId,
                ListingOriginatorOrganisationId = listingOrigOrgId,
                ListingOriginatorDateTime       = listingOrigDateTime
            };

            db.Offers.Add(offer);
            db.SaveChanges();

            //Create Action
            Organisation org = OrganisationHelpers.GetOrganisation(db, currentUser.OrganisationId);

            NotificationHelpers.CreateNotification(db, NotificationTypeEnum.NewOfferReceived, "New offer received from " + org.OrganisationName, offer.OfferId, listingOrigAppUserId, listingOrigOrgId, user);

            return(offer);
        }
예제 #3
0
        public static OfferManageView GetOfferManageViewForOffer(ApplicationDbContext db, Offer offer, IPrincipal user)
        {
            AppUser offerAppUser = AppUserHelpers.GetAppUser(db, offer.OfferOriginatorAppUserId);

            AvailableListing   availableListing   = null;
            RequirementListing requirementListing = null;
            AppUser            listingAppUser     = null;

            switch (offer.ListingType)
            {
            case ListingTypeEnum.Available:
                availableListing = AvailableListingHelpers.GetAvailableListing(db, offer.ListingId);
                listingAppUser   = AppUserHelpers.GetAppUser(db, availableListing.ListingOriginatorAppUserId);
                break;

            case ListingTypeEnum.Requirement:
                requirementListing = RequirementListingHelpers.GetRequirementListing(db, offer.ListingId);
                listingAppUser     = AppUserHelpers.GetAppUser(db, requirementListing.ListingOriginatorAppUserId);
                break;
            }

            OfferManageView offerManageView = new OfferManageView()
            {
                OfferDetails              = offer,
                AvailableListingDetails   = availableListing,
                RequirementListingDetails = requirementListing,
                OfferAppUserDetails       = offerAppUser,
                ListingAppUserDetails     = listingAppUser,
                OfferBranchDetails        = BranchHelpers.GetBranch(db, offerAppUser.CurrentBranchId),
                ListingBranchDetails      = BranchHelpers.GetBranch(db, listingAppUser.CurrentBranchId),
                OfferAppUserSettings      = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, offerAppUser.AppUserId),
                ListingAppUserSettings    = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, listingAppUser.AppUserId)
            };

            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
            offerManageView.InhouseOffer = OfferProcessHelpers.SetInhouseFlag(offer, thisAppUser, thisCompany);

            //set buttons
            bool?displayAcceptButton  = null;
            bool?displayRejectButton  = null;
            bool?displayCounterButton = null;
            bool?displayOfferButton   = null;

            OfferProcessHelpers.SetOrderButtons(db, user, offerManageView, out displayAcceptButton, out displayRejectButton, out displayCounterButton, out displayOfferButton);

            offerManageView.DisplayAcceptButton  = displayAcceptButton;
            offerManageView.DisplayRejectButton  = displayRejectButton;
            offerManageView.DisplayCounterButton = displayCounterButton;
            offerManageView.DisplayOfferButton   = displayOfferButton;

            return(offerManageView);
        }
예제 #4
0
        public static Order CreateOrder(ApplicationDbContext db, Offer offer, IPrincipal user)
        {
            AppUser appUser = AppUserHelpers.GetAppUser(db, user);

            decimal orderQty = 0.00M;

            switch (offer.OfferStatus)
            {
            case OfferStatusEnum.New:
            case OfferStatusEnum.Reoffer:
                orderQty = offer.CurrentOfferQuantity;
                break;

            case OfferStatusEnum.Countered:
                orderQty = offer.CounterOfferQuantity.Value;
                break;
            }

            //Update Listing values
            switch (offer.ListingType)
            {
            case ListingTypeEnum.Available:
                AvailableListingHelpers.UpdateAvailableListingQuantities(db, offer.ListingId, ListingQuantityChange.Subtract, orderQty, user);
                break;

            case ListingTypeEnum.Requirement:
                RequiredListingHelpers.UpdateRequiredListingQuantities(db, offer.ListingId, ListingQuantityChange.Subtract, orderQty, user);
                break;
            }

            Order order = new Order()
            {
                OrderId                         = Guid.NewGuid(),
                ItemDescription                 = offer.ItemDescription,
                ListingType                     = offer.ListingType,
                OrderQuanity                    = orderQty,
                OrderInStatus                   = OrderInStatusEnum.New,
                OrderOutStatus                  = OrderOutStatusEnum.New,
                OrderCreationDateTime           = DateTime.Now,
                OrderOriginatorAppUserId        = appUser.AppUserId,
                OrderOriginatorOrganisationId   = appUser.OrganisationId,
                OrderOriginatorDateTime         = DateTime.Now,
                OfferId                         = offer.OfferId,
                OfferOriginatorAppUserId        = offer.LastOfferOriginatorAppUserId ?? offer.OfferOriginatorAppUserId,
                OfferOriginatorOrganisationId   = offer.OfferOriginatorOrganisationId,
                ListingId                       = offer.ListingId,
                ListingOriginatorAppUserId      = offer.ListingOriginatorAppUserId,
                ListingOriginatorOrganisationId = offer.ListingOriginatorOrganisationId
            };

            db.Orders.Add(order);
            db.SaveChanges();

            return(order);
        }
예제 #5
0
        public static DashboardView GetDashboardViewLogin(ApplicationDbContext db, IPrincipal user)
        {
            AppUser appUser = AppUserHelpers.GetAppUser(db, user);

            //initialise the view
            DashboardView dashboardView = new DashboardView();

            //get the campaigns and listings for this user
            List <Campaign> campaignsForUser = CampaignHelpers.GetAllCampaignsForUser(db, appUser.AppUserId, false);

            dashboardView.CampaignList = campaignsForUser;

            List <Campaign> campaignsDashboardList = CampaignHelpers.GetAllDashboardFilteredCampaigns(db, appUser.AppUserId);

            dashboardView.CampaignDashboardList = campaignsDashboardList;

            List <RequirementListing> requirementListingsForUser = RequirementListingHelpers.GetAllRequirementListingsForUser(db, appUser.AppUserId, false);

            dashboardView.RequirementListingList = requirementListingsForUser;

            List <RequirementListing> requirementListingDashboardList = RequirementListingHelpers.GetAllDashboardFilteredRequirementListings(db, appUser.AppUserId);

            dashboardView.RequirementListingDashboardList = requirementListingDashboardList;

            List <AvailableListing> availableListingsForUser = AvailableListingHelpers.GetAllAvailableListingsForUser(db, appUser.AppUserId, false);

            dashboardView.AvailableListingList = availableListingsForUser;

            List <AvailableListing> availableListingDashboardList = AvailableListingHelpers.GetAllDashboardFilteredAvailableListings(db, appUser.AppUserId);

            dashboardView.AvailableListingDashboardList = availableListingDashboardList;

            List <Offer> offersForUser = OfferHelpers.GetAllOffersForUser(db, appUser.AppUserId, false);

            dashboardView.OfferList = offersForUser;

            List <Order> ordersForUser = OrderHelpers.GetAllOrdersForUser(db, appUser.AppUserId, false);

            dashboardView.OrderList = ordersForUser;

            //get listings for admin areas if this user is not a 'User' - i.e. is Manager, Admin etc.
            if (user.Identity.GetCurrentUserRole() != "User")
            {
                List <UserTask> tasksForUser = UserTaskHelpers.GetUserTasksForUser(db, appUser.AppUserId);
                //LSLSLS get list of 'actions' once written

                dashboardView.UserTaskList = tasksForUser;
            }

            return(dashboardView);
        }
예제 #6
0
        //Build a NotificationsViewModel record from a Notification
        public static NotificationViewModel CreateNotificationsViewModel(ApplicationDbContext db, Notification notification)
        {
            string referenceInfo = "";

            switch (notification.NotificationType)
            {
            case NotificationTypeEnum.NewOfferReceived:
                Offer offer1 = OfferHelpers.GetOffer(db, notification.ReferenceKey);
                referenceInfo = offer1.ItemDescription + " x " + offer1.CurrentOfferQuantity.ToString();
                break;

            case NotificationTypeEnum.CounterOfferReceived:
                Offer offer2 = OfferHelpers.GetOffer(db, notification.ReferenceKey);
                referenceInfo = offer2.ItemDescription + " x " + offer2.CounterOfferQuantity.ToString();
                break;

            case NotificationTypeEnum.NewOrderReceived:
                Order order = OrderHelpers.GetOrder(db, notification.ReferenceKey);
                switch (order.ListingType)
                {
                case ListingTypeEnum.Available:
                    AvailableListing listingA = AvailableListingHelpers.GetAvailableListing(db, order.ListingId.Value);
                    referenceInfo = listingA.ItemDescription = " x " + order.OrderQuanity;
                    break;

                case ListingTypeEnum.Requirement:
                    RequiredListing listingB = RequiredListingHelpers.GetRequiredListing(db, order.ListingId.Value);
                    referenceInfo = listingB.ItemDescription = " x " + order.OrderQuanity;
                    break;
                }
                break;
            }

            //build view
            NotificationViewModel view = new NotificationViewModel()
            {
                NotificationId          = notification.NotificationId,
                NotificationType        = notification.NotificationType,
                NotificationDescription = notification.NotificationDescription,
                ReferenceInformation    = referenceInfo,
                AppUser   = AppUserHelpers.GetAppUser(db, notification.AppUserId.Value),
                ChangedOn = notification.RecordChangeOn,
                ChangedBy = AppUserHelpers.GetAppUserName(db, notification.RecordChangeBy)
            };

            return(view);
        }
예제 #7
0
        public static decimal GetListingQuantityForListingIdListingType(ApplicationDbContext db, Guid listingId, ListingTypeEnum listingType)
        {
            decimal quantityOutstanding = 0.00M;

            switch (listingType)
            {
            case ListingTypeEnum.Available:
                quantityOutstanding = AvailableListingHelpers.GetAvailableListing(db, listingId).QuantityOutstanding;
                break;

            case ListingTypeEnum.Requirement:
                quantityOutstanding = RequiredListingHelpers.GetRequiredListing(db, listingId).QuantityOutstanding;
                break;
            }

            return(quantityOutstanding);
        }
예제 #8
0
        public static List <AvailableListingManageView> GetAllAvailableListingsManageViewForUserBranch(ApplicationDbContext db, IPrincipal user)
        {
            List <AvailableListingManageView> allAvailableListingsManageView = new List <AvailableListingManageView>();

            BranchUser branchUser = BranchUserHelpers.GetBranchUserCurrentForUser(db, user);
            List <AvailableListing> allAvailableListingsForBranchUser = AvailableListingHelpers.GetAllAvailableListingsForBranchUser(db, branchUser);

            foreach (AvailableListing AvailableListingForBranchUser in allAvailableListingsForBranchUser)
            {
                AvailableListingManageView AvailableListingManageView = new AvailableListingManageView()
                {
                    AvailableListing = AvailableListingForBranchUser
                };

                allAvailableListingsManageView.Add(AvailableListingManageView);
            }

            return(allAvailableListingsManageView);
        }
예제 #9
0
        public static List <AvailableListingManageView> GetAllAvailableListingsManageView(ApplicationDbContext db, IPrincipal user, bool getHistory)
        {
            List <AvailableListingManageView> allAvailableListingsManageView = new List <AvailableListingManageView>();

            AppUser appUser = AppUserHelpers.GetAppUser(db, user);
            List <AvailableListing> allAvailableListingsForUser = AvailableListingHelpers.GetAllManageListingFilteredAvailableListings(db, appUser.AppUserId, getHistory);

            foreach (AvailableListing AvailableListingForBranchUser in allAvailableListingsForUser)
            {
                AvailableListingManageView AvailableListingManageView = new AvailableListingManageView()
                {
                    AvailableListing = AvailableListingForBranchUser
                };

                allAvailableListingsManageView.Add(AvailableListingManageView);
            }

            return(allAvailableListingsManageView);
        }
예제 #10
0
        public static AvailableListingEditView GetAvailableListingEditView(ApplicationDbContext db, Guid listingId, IPrincipal user)
        {
            AvailableListing availableListing = AvailableListingHelpers.GetAvailableListing(db, listingId);
            AppUser          listingAppUser   = AppUserHelpers.GetAppUser(db, availableListing.ListingOriginatorAppUserId);
            Branch           listingBranch    = BranchHelpers.GetBranch(db, availableListing.ListingOriginatorBranchId);
            Company          listingCompany   = CompanyHelpers.GetCompany(db, availableListing.ListingOriginatorCompanyId);

            ViewButtons buttons = ViewButtonsHelpers.GetAvailableButtonsForSingleView(db, listingAppUser, listingBranch, listingCompany, user);

            AvailableListingEditView view = new AvailableListingEditView()
            {
                ListingId           = availableListing.ListingId,
                ItemDescription     = availableListing.ItemDescription,
                ItemCategory        = availableListing.ItemCategory,
                ItemType            = availableListing.ItemType,
                QuantityRequired    = availableListing.QuantityRequired,
                QuantityFulfilled   = availableListing.QuantityFulfilled,
                QuantityOutstanding = availableListing.QuantityOutstanding,
                UoM                       = availableListing.UoM,
                AvailableFrom             = availableListing.AvailableFrom,
                AvailableTo               = availableListing.AvailableTo,
                ItemCondition             = availableListing.ItemCondition,
                DisplayUntilDate          = availableListing.DisplayUntilDate,
                SellByDate                = availableListing.SellByDate,
                UseByDate                 = availableListing.UseByDate,
                DeliveryAvailable         = availableListing.DeliveryAvailable,
                ListingStatus             = availableListing.ListingStatus,
                ListingOriginatorDateTime = availableListing.ListingOriginatorDateTime,
                ListingAppUser            = listingAppUser,
                ListingBranchDetails      = listingBranch,
                ListingCompanyDetails     = listingCompany,
                Buttons                   = buttons
            };

            return(view);
        }
예제 #11
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);
        }
예제 #12
0
        public static Order CreateOrder(ApplicationDbContext db, IPrincipal user, Offer offer)
        {
            BranchUser branchUser = BranchUserHelpers.GetBranchUserCurrentForUser(db, user);

            //depending on 'branch trading' check to see if last counter is related to this user, if not then use the last counter details (if counter details exist)
            if (offer.LastCounterOfferOriginatorAppUserId != null)
            {
                Company company = CompanyHelpers.GetCompany(db, branchUser.CompanyId);

                if (company.AllowBranchTrading)
                {
                    if (branchUser.BranchId != offer.LastCounterOfferOriginatorBranchId)
                    {
                        branchUser = BranchUserHelpers.GetBranchUser(db, offer.LastCounterOfferOriginatorAppUserId.Value, offer.LastCounterOfferOriginatorBranchId.Value, offer.LastCounterOfferOriginatorCompanyId.Value);
                    }
                }
                else
                {
                    if (branchUser.CompanyId != offer.LastCounterOfferOriginatorCompanyId)
                    {
                        branchUser = BranchUserHelpers.GetBranchUser(db, offer.LastCounterOfferOriginatorAppUserId.Value, offer.LastCounterOfferOriginatorBranchId.Value, offer.LastCounterOfferOriginatorCompanyId.Value);
                    }
                }
            }

            decimal orderQty = offer.CurrentOfferQuantity;

            if (offer.CurrentOfferQuantity == 0 && offer.CounterOfferQuantity != 0)
            {
                orderQty = offer.CounterOfferQuantity.Value;
            }

            Order order = new Order()
            {
                OrderId                    = Guid.NewGuid(),
                ListingType                = offer.ListingType,
                OrderQuanity               = orderQty,
                OrderStatus                = OrderStatusEnum.New,
                OrderCreationDateTime      = DateTime.Now,
                OrderOriginatorAppUserId   = branchUser.UserId,
                OrderOriginatorBranchId    = branchUser.BranchId,
                OrderOriginatorCompanyId   = branchUser.CompanyId,
                OrderOriginatorDateTime    = DateTime.Now,
                OfferId                    = offer.OfferId,
                OfferOriginatorAppUserId   = offer.OfferOriginatorAppUserId,
                OfferOriginatorBranchId    = offer.OfferOriginatorBranchId,
                OfferOriginatorCompanyId   = offer.OfferOriginatorCompanyId,
                ListingId                  = offer.ListingId,
                ListingOriginatorAppUserId = offer.ListingOriginatorAppUserId,
                ListingOriginatorBranchId  = offer.ListingOriginatorBranchId,
                ListingOriginatorCompanyId = offer.ListingOriginatorCompanyId
            };

            db.Orders.Add(order);

            //Update the quantities on listing

            switch (offer.ListingType)
            {
            case ListingTypeEnum.Available:
                AvailableListingHelpers.UpdateQuantitiesFromOrder(db, offer);
                break;

            case ListingTypeEnum.Requirement:
                RequirementListingHelpers.UpdateQuantitiesFromOrder(db, offer);
                break;
            }

            db.SaveChanges();

            return(order);
        }
예제 #13
0
        public static List <AvailableListingGeneralInfoView> GetAllAvailableListingsGeneralInfoView(ApplicationDbContext db, IPrincipal user)
        {
            List <AvailableListingGeneralInfoView> allAvailableListingsGeneralInfoView = new List <AvailableListingGeneralInfoView>();

            AppUser         appUser       = AppUserHelpers.GetAppUser(db, user);
            AppUserSettings settings      = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, appUser.AppUserId);
            Branch          currentBranch = BranchHelpers.GetBranch(appUser.CurrentBranchId);

            List <AvailableListing> allAvailableListings = AvailableListingHelpers.GetAllGeneralInfoFilteredAvailableListings(db, appUser.AppUserId);

            foreach (AvailableListing availableListing in allAvailableListings)
            {
                //Find any related offers
                Offer   offer    = OfferHelpers.GetOfferForListingAndUser(db, availableListing.ListingId, appUser.AppUserId);
                decimal offerQty = 0M;
                if (offer != null)
                {
                    offerQty = offer.CurrentOfferQuantity;
                }

                bool userBlocked    = false;
                bool branchBlocked  = false;
                bool companyBlocked = false;

                BlockHelpers.GetBlocksForAllTypesForSpecificOfBy(db, availableListing.ListingOriginatorAppUserId, appUser.AppUserId, availableListing.ListingOriginatorBranchId, currentBranch.BranchId, availableListing.ListingOriginatorCompanyId, currentBranch.CompanyId, out userBlocked, out branchBlocked, out companyBlocked);

                bool userMatchedOwner    = false;
                bool branchMatchedOwner  = false;
                bool companyMatchedOwner = false;

                if (currentBranch.CompanyId == availableListing.ListingOriginatorCompanyId)
                {
                    companyMatchedOwner = true;
                }
                if (currentBranch.BranchId == availableListing.ListingOriginatorBranchId)
                {
                    branchMatchedOwner = true;
                }
                if (appUser.AppUserId == availableListing.ListingOriginatorAppUserId)
                {
                    userMatchedOwner = true;
                }

                Company company = CompanyHelpers.GetCompany(db, availableListing.ListingOriginatorCompanyId);

                AvailableListingGeneralInfoView AvailableListingGeneralInfoView = new AvailableListingGeneralInfoView()
                {
                    AvailableListing        = availableListing,
                    OfferQuantity           = offerQty,
                    AllowBranchTrading      = company.AllowBranchTrading,
                    UserLevelBlock          = userBlocked,
                    BranchLevelBlock        = branchBlocked,
                    CompanyLevelBlock       = companyBlocked,
                    DisplayBlocks           = settings.AvailableListingGeneralInfoDisplayBlockedListings,
                    CompanyLevelOwner       = companyMatchedOwner,
                    DisplayMyCompanyRecords = settings.AvailableListingGeneralInfoDisplayMyUserListings,
                    BranchLevelOwner        = branchMatchedOwner,
                    DisplayMyBranchRecords  = settings.AvailableListingGeneralInfoDisplayMyBranchListings,
                    UserLevelOwner          = userMatchedOwner,
                    DisplayMyRecords        = settings.AvailableListingGeneralInfoDisplayMyUserListings
                };

                allAvailableListingsGeneralInfoView.Add(AvailableListingGeneralInfoView);
            }

            return(allAvailableListingsGeneralInfoView);
        }
        public static AvailableListingDetailsViewModel CreateAvailableListingDetailsViewModel(ApplicationDbContext db, Guid listingId, string breadcrumb, bool displayOnly, HttpRequestBase request, string controllerValue, string actionValue, string callingActionDisplayName, Dictionary <int, string> breadcrumbDictionary, bool?recalled, IPrincipal user, int?maxDistance, double?maxAge)
        {
            AvailableListing listing = AvailableListingHelpers.GetAvailableListing(db, listingId);

            if (listing != null)
            {
                //Set up the calling fields
                if (!recalled.HasValue)
                {
                    GeneralHelpers.GetCallingDetailsFromRequest(request, controllerValue, actionValue, out controllerValue, out actionValue);
                }

                AppUser recordChangedBy          = AppUserHelpers.GetAppUser(db, listing.RecordChangeBy);
                AppUser listingOriginatorAppUser = AppUserHelpers.GetAppUser(db, listing.ListingOriginatorAppUserId);

                AvailableListingDetailsViewModel model = new AvailableListingDetailsViewModel()
                {
                    MaxDistance         = maxDistance,
                    MaxAge              = maxAge,
                    Breadcrumb          = breadcrumb,
                    DisplayOnly         = displayOnly,
                    ListingId           = listing.ListingId,
                    ItemDescription     = listing.ItemDescription,
                    ItemCategory        = listing.ItemCategory,
                    ItemType            = listing.ItemType,
                    QuantityAvailable   = listing.QuantityAvailable,
                    QuantityFulfilled   = listing.QuantityFulfilled,
                    QuantityOutstanding = listing.QuantityOutstanding,
                    UoM                           = listing.UoM,
                    AvailableFrom                 = listing.AvailableFrom,
                    AvailableTo                   = listing.AvailableTo,
                    ItemCondition                 = listing.ItemCondition,
                    DisplayUntilDate              = listing.DisplayUntilDate,
                    SellByDate                    = listing.SellByDate,
                    UseByDate                     = listing.UseByDate,
                    DeliveryAvailable             = listing.DeliveryAvailable,
                    ListingStatus                 = listing.ListingStatus,
                    ListingOrganisationPostcode   = listing.ListingOrganisationPostcode,
                    RecordChange                  = listing.RecordChange,
                    RecordChangeOn                = listing.RecordChangeOn,
                    RecordChangeByName            = recordChangedBy.FirstName + " " + recordChangedBy.LastName,
                    RecordChangeByEmail           = recordChangedBy.LoginEmail,
                    ListingOriginatorAppUserName  = listingOriginatorAppUser.FirstName + " " + listingOriginatorAppUser.LastName,
                    ListingOriginatorAppUserEmail = listingOriginatorAppUser.LoginEmail,
                    ListingOriginatorDateTime     = listing.ListingOriginatorDateTime,
                    CallingController             = controllerValue,
                    CallingAction                 = actionValue,
                    CallingActionDisplayName      = callingActionDisplayName,
                    BreadcrumbTrail               = breadcrumbDictionary
                };

                if (controllerValue == "GeneralInfo" && actionValue == "Available")
                {
                    //Get user info for the offer side of the display
                    AppUser      currentUser = AppUserHelpers.GetAppUser(db, user);
                    Organisation currentOrg  = OrganisationHelpers.GetOrganisation(db, currentUser.OrganisationId);

                    Offer offer = OfferHelpers.GetOfferForListingByUser(db, listing.ListingId, currentUser.AppUserId, currentOrg.OrganisationId, currentOrg.ListingPrivacyLevel);

                    if (offer == null)
                    {
                        model.OfferDescription = "Make an offer";
                    }
                    else
                    {
                        model.OfferDescription = "Current offer";
                        model.OfferId          = offer.OfferId;
                        model.OfferQty         = offer.CurrentOfferQuantity;
                        model.OfferCounterQty  = offer.CounterOfferQuantity;
                        model.OfferStatus      = offer.OfferStatus;
                    }
                }

                return(model);
            }
            else
            {
                return(null);
            }
        }
예제 #15
0
        public static OrderViewModel GetOfferViewModel(ApplicationDbContext db, HttpRequestBase request, Guid orderId, string breadcrumb, string callingActionDisplayName, bool displayOnly, string type, bool?recalled, string controllerValue, string actionValue, IPrincipal user)
        {
            AppUser currentUser = AppUserHelpers.GetAppUser(db, user);

            Dictionary <int, string> breadcrumbDictionary = new Dictionary <int, string>();

            breadcrumbDictionary.Add(0, breadcrumb);

            if (!recalled.HasValue || recalled.Value != true)
            {
                GeneralHelpers.GetCallingDetailsFromRequest(request, controllerValue, actionValue, out controllerValue, out actionValue);
            }

            Order order = OrderHelpers.GetOrder(db, orderId);

            string       itemDescription = "";
            ItemTypeEnum itemType        = ItemTypeEnum.Canned;
            string       uoM             = "";

            if (order.ListingType == ListingTypeEnum.Available)
            {
                AvailableListing listing = AvailableListingHelpers.GetAvailableListing(db, order.ListingId.Value);
                itemDescription = listing.ItemDescription;
                itemType        = listing.ItemType;
                uoM             = listing.UoM;
            }
            else
            {
                RequiredListing listing = RequiredListingHelpers.GetRequiredListing(db, order.ListingId.Value);
                itemDescription = listing.ItemDescription;
                itemType        = listing.ItemType;
                uoM             = listing.UoM;
            }

            OrderViewModel model = new OrderViewModel()
            {
                DisplayOnly          = displayOnly,
                Breadcrumb           = breadcrumb,
                BreadcrumbDictionary = breadcrumbDictionary,
                Type                          = type,
                OrderId                       = order.OrderId,
                ListingType                   = order.ListingType,
                ItemDescription               = itemDescription,
                ItemType                      = itemType,
                UoM                           = uoM,
                OrderQuanity                  = order.OrderQuanity,
                OrderInStatus                 = order.OrderInStatus,
                OrderOutStatus                = order.OrderOutStatus,
                OrderCreationDateTime         = order.OrderCreationDateTime,
                OrderDistributionDateTime     = order.OrderDistributionDateTime,
                OrderDistributedBy            = AppUserHelpers.GetAppUserName(db, order.OrderDistributedBy),
                OrderDeliveredDateTime        = order.OrderDeliveredDateTime,
                OrderDeliveredBy              = AppUserHelpers.GetAppUserName(db, order.OrderDeliveredBy),
                OrderCollectedDateTime        = order.OrderCollectedDateTime,
                OrderCollectedBy              = AppUserHelpers.GetAppUserName(db, order.OrderCollectedBy),
                OrderReceivedDateTime         = order.OrderReceivedDateTime,
                OrderReceivedBy               = AppUserHelpers.GetAppUserName(db, order.OrderReceivedBy),
                OrderInClosedDateTime         = order.OrderInClosedDateTime,
                OrderInClosedBy               = AppUserHelpers.GetAppUserName(db, order.OrderInClosedBy),
                OrderOutClosedDateTime        = order.OrderOutClosedDateTime,
                OrderOutClosedBy              = AppUserHelpers.GetAppUserName(db, order.OrderOutClosedBy),
                OrderOriginatorAppUser        = AppUserHelpers.GetAppUserName(db, order.OrderOriginatorAppUserId),
                OrderOriginatorOrganisation   = OrganisationHelpers.GetOrganisationName(db, order.OrderOriginatorOrganisationId),
                OrderOriginatorDateTime       = order.OrderOriginatorDateTime,
                OfferId                       = order.OfferId,
                OfferOriginatorAppUser        = AppUserHelpers.GetAppUserName(db, order.OfferOriginatorAppUserId),
                OfferOriginatorOrganisation   = OrganisationHelpers.GetOrganisationName(db, order.OfferOriginatorOrganisationId),
                ListingId                     = order.ListingId,
                ListingOriginatorAppUser      = AppUserHelpers.GetAppUserName(db, order.ListingOriginatorAppUserId),
                ListingOriginatorOrganisation = OrganisationHelpers.GetOrganisationName(db, order.ListingOriginatorOrganisationId),
                CallingAction                 = actionValue,
                CallingActionDisplayName      = callingActionDisplayName,
                CallingController             = controllerValue,
                BreadcrumbTrail               = breadcrumbDictionary
            };

            return(model);
        }