Esempio n. 1
0
        public static Offer UpdateOffer(ApplicationDbContext db, Guid offerid, OfferStatusEnum offerStatus, decimal?currentOfferQuantity, decimal?counterOfferQuantity, IPrincipal user)
        {
            Offer offer = OfferHelpers.GetOffer(db, offerid);

            switch (offerStatus)
            {
            case OfferStatusEnum.Reoffer:     //update offer value and move counter value to previous
                if (currentOfferQuantity.HasValue)
                {
                    offer.CurrentOfferQuantity         = currentOfferQuantity.Value;
                    offer.PreviousCounterOfferQuantity = offer.CounterOfferQuantity;
                    offer.CounterOfferQuantity         = null;
                    offer.LastOfferOriginatorAppUserId = AppUserHelpers.GetAppUserIdFromUser(user);
                    offer.LastOfferOriginatorDateTime  = DateTime.Now;
                    offer.OfferStatus = offerStatus;

                    db.Entry(offer).State = EntityState.Modified;
                    db.SaveChanges();
                }
                break;

            case OfferStatusEnum.Countered:     //update counter value and move current offer to previous offer
                if (counterOfferQuantity.HasValue)
                {
                    offer.CounterOfferQuantity  = counterOfferQuantity;
                    offer.PreviousOfferQuantity = offer.CurrentOfferQuantity;
                    offer.CurrentOfferQuantity  = 0.00M;
                    if (!offer.CounterOfferOriginatorOrganisationId.HasValue)
                    {
                        AppUser appUser = AppUserHelpers.GetAppUser(db, AppUserHelpers.GetAppUserIdFromUser(user));
                        offer.CounterOfferOriginatorAppUserId      = appUser.AppUserId;
                        offer.CounterOfferOriginatorDateTime       = DateTime.Now;
                        offer.CounterOfferOriginatorOrganisationId = appUser.OrganisationId;
                    }
                    else
                    {
                        offer.LastCounterOfferOriginatorAppUserId = AppUserHelpers.GetAppUserIdFromUser(user);
                        offer.LastCounterOfferOriginatorDateTime  = DateTime.Now;
                    }
                    offer.OfferStatus = offerStatus;

                    db.Entry(offer).State = EntityState.Modified;
                    db.SaveChanges();
                }
                break;
            }
            //Create Action
            Organisation org = OrganisationHelpers.GetOrganisation(db, AppUserHelpers.GetAppUser(db, AppUserHelpers.GetAppUserIdFromUser(user)).OrganisationId);

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

            return(offer);
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        public static Offer UpdateStatus(ApplicationDbContext db, Guid offerId, OfferStatusEnum newStatus, IPrincipal user)
        {
            Offer offer = OfferHelpers.GetOffer(db, offerId);

            offer.OfferStatus = newStatus;

            if (newStatus == OfferStatusEnum.ClosedNoStock)
            {
                offer.ClosedNoStockBy = AppUserHelpers.GetAppUserIdFromUser(user);
                offer.ClosedNoStockOn = DateTime.Now;
            }

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

            return(offer);
        }
Esempio n. 4
0
        public static OfferManageView GetOfferManageViewForOffer(ApplicationDbContext db, Guid offerId, IPrincipal user)
        {
            Offer offer = OfferHelpers.GetOffer(db, offerId);

            return(GetOfferManageViewForOffer(db, offer, user));
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        public static OfferViewModel GetOfferViewModel(ApplicationDbContext db, HttpRequestBase request, Guid offerId, 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);
            }

            Offer offer = OfferHelpers.GetOffer(db, offerId);

            OfferViewModel model = new OfferViewModel()
            {
                DisplayOnly          = displayOnly,
                Breadcrumb           = breadcrumb,
                BreadcrumbDictionary = breadcrumbDictionary,
                Type                                 = type,
                OfferId                              = offer.OfferId,
                ListingId                            = offer.ListingId,
                ListingType                          = offer.ListingType,
                OfferStatus                          = offer.OfferStatus,
                ItemDescription                      = offer.ItemDescription,
                QuantityOutstanding                  = OfferViewHelpers.GetListingQuantityForListingIdListingType(db, offer.ListingId, offer.ListingType),
                CurrentOfferQuantity                 = offer.CurrentOfferQuantity,
                PreviousOfferQuantity                = offer.PreviousOfferQuantity,
                CounterOfferQuantity                 = offer.CounterOfferQuantity,
                PreviousCounterOfferQuantity         = offer.PreviousCounterOfferQuantity,
                OfferOriginatorAppUser               = AppUserHelpers.GetAppUserName(db, offer.OfferOriginatorAppUserId),
                OfferOriginatorOrganisation          = OrganisationHelpers.GetOrganisationName(db, offer.OfferOriginatorOrganisationId),
                OfferOriginatorDateTime              = offer.OfferOriginatorDateTime,
                YourOrganisationId                   = currentUser.OrganisationId,
                OfferOriginatorOrganisationId        = offer.OfferOriginatorOrganisationId,
                RejectedBy                           = AppUserHelpers.GetAppUserName(db, offer.RejectedBy),
                RejectedOn                           = offer.RejectedOn,
                LastOfferOriginatorAppUser           = AppUserHelpers.GetAppUserName(db, offer.LastOfferOriginatorAppUserId),
                LastOfferOriginatorDateTime          = offer.LastOfferOriginatorDateTime,
                ListingOriginatorAppUser             = AppUserHelpers.GetAppUserName(db, offer.ListingOriginatorAppUserId),
                ListingOriginatorOrganisation        = OrganisationHelpers.GetOrganisationName(db, offer.ListingOriginatorOrganisationId),
                ListingOriginatorDateTime            = offer.ListingOriginatorDateTime,
                CounterOfferOriginatorAppUser        = AppUserHelpers.GetAppUserName(db, offer.CounterOfferOriginatorAppUserId),
                CounterOfferOriginatorOrganisation   = OrganisationHelpers.GetOrganisationName(db, offer.CounterOfferOriginatorOrganisationId),
                CounterOfferOriginatorDateTime       = offer.CounterOfferOriginatorDateTime,
                CounterOfferOriginatorOrganisationId = offer.CounterOfferOriginatorOrganisationId,
                LastCounterOfferOriginatorAppUser    = AppUserHelpers.GetAppUserName(db, offer.LastCounterOfferOriginatorAppUserId),
                LastCounterOfferOriginatorDateTime   = offer.LastCounterOfferOriginatorDateTime,
                OrderOriginatorAppUser               = AppUserHelpers.GetAppUserName(db, offer.OrderOriginatorAppUserId),
                OrderOriginatorOrganisation          = OrganisationHelpers.GetOrganisationName(db, offer.OrderOriginatorOrganisationId),
                OrderOriginatorDateTime              = offer.OrderOriginatorDateTime,
                CallingAction                        = actionValue,
                CallingActionDisplayName             = callingActionDisplayName,
                CallingController                    = controllerValue,
                BreadcrumbTrail                      = breadcrumbDictionary
            };

            if (displayOnly)
            {
                model.EditableQuantity = false;
            }
            else
            {
                if (type == "created")
                {
                    model.EditableQuantity = offer.CurrentOfferQuantity == 0;
                }
                else if (type == "received")
                {
                    model.EditableQuantity = offer.CurrentOfferQuantity > 0;
                }
            }

            return(model);
        }