コード例 #1
0
        public static AvailableListing CreateAvailableListing(ApplicationDbContext db, IPrincipal user, string itemDescription, ItemCategoryEnum itemCategory, ItemTypeEnum itemType, decimal quantityRequired, string uom, DateTime?availableFrom, DateTime?availableTo, ItemConditionEnum itemCondition, DateTime?displayUntilDate, DateTime?sellByDate, DateTime?useByDate, bool?deliveryAvailable, ItemRequiredListingStatusEnum listingStatus)
        {
            BranchUser branchUser = BranchUserHelpers.GetBranchUserCurrentForUser(db, user);
            Branch     branch     = BranchHelpers.GetBranch(db, branchUser.BranchId);

            AvailableListing AvailableListing = new AvailableListing()
            {
                ListingId           = Guid.NewGuid(),
                ItemDescription     = itemDescription,
                ItemCategory        = itemCategory,
                ItemType            = itemType,
                QuantityRequired    = quantityRequired,
                QuantityFulfilled   = 0,
                QuantityOutstanding = quantityRequired,
                UoM                        = uom,
                AvailableFrom              = availableFrom,
                AvailableTo                = availableTo,
                ItemCondition              = itemCondition,
                DisplayUntilDate           = displayUntilDate,
                SellByDate                 = sellByDate,
                UseByDate                  = useByDate,
                DeliveryAvailable          = deliveryAvailable ?? false,
                ListingBranchPostcode      = branch.AddressPostcode,
                ListingOriginatorAppUserId = branchUser.UserId,
                ListingOriginatorBranchId  = branchUser.BranchId,
                ListingOriginatorCompanyId = branchUser.CompanyId,
                ListingOriginatorDateTime  = DateTime.Now,
                ListingStatus              = ItemRequiredListingStatusEnum.Open
            };

            db.AvailableListings.Add(AvailableListing);
            db.SaveChanges();

            return(AvailableListing);
        }
コード例 #2
0
ファイル: OfferHelpers.cs プロジェクト: leesole/Distributor
        public static Offer CreateOfferForRequirement(ApplicationDbContext db, IPrincipal user, RequirementListing requirementListing, decimal offerQuantity)
        {
            BranchUser branchUser = BranchUserHelpers.GetBranchUserCurrentForUser(db, user);

            Offer offer = new Offer()
            {
                OfferId                    = Guid.NewGuid(),
                ListingId                  = requirementListing.ListingId,
                ListingType                = ListingTypeEnum.Requirement,
                OfferStatus                = OfferStatusEnum.New,
                CurrentOfferQuantity       = offerQuantity,
                OfferOriginatorAppUserId   = branchUser.UserId,
                OfferOriginatorBranchId    = branchUser.BranchId,
                OfferOriginatorCompanyId   = branchUser.CompanyId,
                OfferOriginatorDateTime    = DateTime.Now,
                ListingOriginatorAppUserId = requirementListing.ListingOriginatorAppUserId,
                ListingOriginatorBranchId  = requirementListing.ListingOriginatorBranchId,
                ListingOriginatorCompanyId = requirementListing.ListingOriginatorCompanyId,
                ListingOriginatorDateTime  = requirementListing.ListingOriginatorDateTime
            };

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

            return(offer);
        }
コード例 #3
0
        public static RequirementListing CreateRequirementListing(ApplicationDbContext db, IPrincipal user, string itemDescription, ItemCategoryEnum itemCategory, ItemTypeEnum itemType, decimal quantityRequired, string uom, DateTime?requiredFrom, DateTime?requiredTo, bool acceptDamagedItems, bool acceptOutOfDateItems, bool collectionAvailable, ItemRequiredListingStatusEnum listingStatus, Guid?selectedCampaignId)
        {
            BranchUser branchUser = BranchUserHelpers.GetBranchUserCurrentForUser(db, user);
            Branch     branch     = BranchHelpers.GetBranch(db, branchUser.BranchId);

            RequirementListing requirementListing = new RequirementListing()
            {
                ListingId           = Guid.NewGuid(),
                ItemDescription     = itemDescription,
                ItemCategory        = itemCategory,
                ItemType            = itemType,
                QuantityRequired    = quantityRequired,
                QuantityFulfilled   = 0,
                QuantityOutstanding = quantityRequired,
                UoM                        = uom,
                RequiredFrom               = requiredFrom,
                RequiredTo                 = requiredTo,
                AcceptDamagedItems         = acceptDamagedItems,
                AcceptOutOfDateItems       = acceptOutOfDateItems,
                CollectionAvailable        = collectionAvailable,
                ListingBranchPostcode      = branch.AddressPostcode,
                ListingOriginatorAppUserId = branchUser.UserId,
                ListingOriginatorBranchId  = branchUser.BranchId,
                ListingOriginatorCompanyId = branchUser.CompanyId,
                ListingOriginatorDateTime  = DateTime.Now,
                ListingStatus              = ItemRequiredListingStatusEnum.Open,
                CampaignId                 = selectedCampaignId
            };

            db.RequirementListings.Add(requirementListing);
            db.SaveChanges();

            return(requirementListing);
        }
コード例 #4
0
ファイル: OfferHelpers.cs プロジェクト: leesole/Distributor
        public static Offer UpdateCounterOffer(ApplicationDbContext db, IPrincipal user, Offer offer, decimal offerQuantity)
        {
            BranchUser branchUser = BranchUserHelpers.GetBranchUserCurrentForUser(db, user);

            offer.CounterOfferQuantity  = offerQuantity;
            offer.PreviousOfferQuantity = offer.CurrentOfferQuantity;
            offer.CurrentOfferQuantity  = 0;
            offer.LastCounterOfferOriginatorAppUserId = branchUser.UserId;
            offer.LastCounterOfferOriginatorBranchId  = branchUser.BranchId;
            offer.LastCounterOfferOriginatorCompanyId = branchUser.CompanyId;
            offer.LastCounterOfferOriginatorDateTime  = DateTime.Now;

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

            return(offer);
        }
コード例 #5
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);
        }
コード例 #6
0
        public static List <CampaignManageView> GetAllCampaignsManageViewForUserBranch(ApplicationDbContext db, IPrincipal user)
        {
            List <CampaignManageView> allCampaignsManageView = new List <CampaignManageView>();

            BranchUser      branchUser = BranchUserHelpers.GetBranchUserCurrentForUser(db, user);
            List <Campaign> allCampaignsForBranchUser = CampaignHelpers.GetAllCampaignsForBranchUser(db, branchUser);

            foreach (Campaign campaignForBranchUser in allCampaignsForBranchUser)
            {
                CampaignManageView campaignManageView = new CampaignManageView()
                {
                    Campaign = campaignForBranchUser
                };

                allCampaignsManageView.Add(campaignManageView);
            }

            return(allCampaignsManageView);
        }
コード例 #7
0
        public static Campaign CreateCampaign(ApplicationDbContext db, IPrincipal user, string name, string strapLine, string description, byte[] image, string imageLocation, string website, DateTime?campaignStartDateTime, DateTime?campaignEndDateTime, string locationName, string locationAddressLine1, string locationAddressLine2, string locationAddressLine3, string locationAddressTownCity, string locationAddressCounty, string locationAddressPostcode, string locationTelephoneNumber, string locationEmail, string locationContactName, EntityStatusEnum entityStatus)
        {
            BranchUser branchUser = BranchUserHelpers.GetBranchUserCurrentForUser(db, user);

            Campaign campaign = new Campaign()
            {
                CampaignId                  = Guid.NewGuid(),
                Name                        = name,
                StrapLine                   = strapLine,
                Description                 = description,
                Image                       = image,
                ImageLocation               = imageLocation,
                Website                     = website,
                CampaignStartDateTime       = campaignStartDateTime,
                CampaignEndDateTime         = campaignEndDateTime,
                LocationName                = locationName,
                LocationAddressLine1        = locationAddressLine1,
                LocationAddressLine2        = locationAddressLine2,
                LocationAddressLine3        = locationAddressLine3,
                LocationAddressTownCity     = locationAddressTownCity,
                LocationAddressCounty       = locationAddressCounty,
                LocationAddressPostcode     = locationAddressPostcode,
                LocationTelephoneNumber     = locationTelephoneNumber,
                LocationEmail               = locationEmail,
                LocationContactName         = locationContactName,
                EntityStatus                = entityStatus,
                CampaignOriginatorAppUserId = branchUser.UserId,
                CampaignOriginatorBranchId  = branchUser.BranchId,
                CampaignOriginatorCompanyId = branchUser.CompanyId,
                CampaignOriginatorDateTime  = DateTime.Now
            };

            db.Campaigns.Add(campaign);
            db.SaveChanges();

            return(campaign);
        }
コード例 #8
0
ファイル: OrderHelpers.cs プロジェクト: leesole/Distributor
        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);
        }