コード例 #1
0
        public static Offer AcceptOffer(ApplicationDbContext db, Guid offerId, IPrincipal user)
        {
            Offer   offer   = db.Offers.Find(offerId);
            AppUser appUser = AppUserHelpers.GetAppUser(db, user);

            Order order = OrderHelpers.CreateOrder(db, offer, user);

            offer.OfferStatus = OfferStatusEnum.Accepted;
            offer.AcceptedBy  = appUser.AppUserId;
            offer.AcceptedOn  = DateTime.Now;
            offer.OrderId     = order.OrderId;
            offer.OrderOriginatorAppUserId      = appUser.AppUserId;
            offer.OrderOriginatorOrganisationId = appUser.OrganisationId;
            offer.OrderOriginatorDateTime       = DateTime.Now;

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

            //set any related actions to Closed
            NotificationHelpers.RemoveNotificationsForOffer(db, offerId, user);

            //set any related current offers to closed if there is no stock left (currentOfferQuantity = 0)
            if (offer.CurrentOfferQuantity == 0)
            {
                OfferHelpers.CloseOffersRelatedToListing(db, offer.ListingId, user);
            }

            //Create Action to show order ready
            Organisation org = OrganisationHelpers.GetOrganisation(db, offer.OfferOriginatorOrganisationId);

            NotificationHelpers.CreateNotification(db, NotificationTypeEnum.NewOrderReceived, "New order received from " + org.OrganisationName, order.OrderId, appUser.AppUserId, org.OrganisationId, user);

            return(offer);
        }
コード例 #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 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);
        }
コード例 #4
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);
        }