public static RequirementListing UpdateQuantitiesFromOrder(ApplicationDbContext db, Offer offer) { decimal orderQty = offer.CurrentOfferQuantity; if (offer.CurrentOfferQuantity == 0 && offer.CounterOfferQuantity != 0) { orderQty = offer.CounterOfferQuantity.Value; } RequirementListing listing = GetRequirementListing(db, offer.ListingId); listing.QuantityFulfilled += orderQty; listing.QuantityOutstanding -= orderQty; listing.ListingStatus = ItemRequiredListingStatusEnum.Partial; if (listing.QuantityOutstanding <= 0) { listing.ListingStatus = ItemRequiredListingStatusEnum.Complete; } db.Entry(listing).State = EntityState.Modified; db.SaveChanges(); return(listing); }
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); }
public static Offer CreateOfferForRequirement(IPrincipal user, RequirementListing requirementListing, decimal offerQuantity) { ApplicationDbContext db = new ApplicationDbContext(); Offer offer = CreateOfferForRequirement(db, user, requirementListing, offerQuantity); db.Dispose(); return(offer); }
public static RequirementListing UpdateRequirementListingFromRequirementListingEditView(RequirementListingEditView view) { ApplicationDbContext db = new ApplicationDbContext(); RequirementListing listing = UpdateRequirementListingFromRequirementListingEditView(db, view); db.Dispose(); return(listing); }
public static RequirementListing UpdateQuantitiesFromOrder(Offer offer) { ApplicationDbContext db = new ApplicationDbContext(); RequirementListing listing = UpdateQuantitiesFromOrder(db, offer); db.Dispose(); return(listing); }
public static RequirementListing CreateRequirementListingFromRequirementListingAddView(RequirementListingAddView requirementListingAddView, IPrincipal user) { ApplicationDbContext db = new ApplicationDbContext(); RequirementListing newCampaign = CreateRequirementListingFromRequirementListingAddView(db, requirementListingAddView, user); db.Dispose(); return(newCampaign); }
public static RequirementListing CreateRequirementListing(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) { ApplicationDbContext db = new ApplicationDbContext(); RequirementListing newRequirementListing = CreateRequirementListing(db, user, itemDescription, itemCategory, itemType, quantityRequired, uom, requiredFrom, requiredTo, acceptDamagedItems, acceptOutOfDateItems, collectionAvailable, listingStatus, selectedCampaignId); db.Dispose(); return(newRequirementListing); }
public static RequirementListing GetRequirementListing(Guid listingId) { ApplicationDbContext db = new ApplicationDbContext(); RequirementListing requirement = GetRequirementListing(db, listingId); db.Dispose(); return(requirement); }
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); }
public ActionResult SubmitRequirementOffer(Guid?listingId, decimal?offerQuantity) { if (listingId.HasValue && offerQuantity.HasValue) { if (offerQuantity > 0) { RequirementListing requirementListing = RequirementListingHelpers.GetRequirementListing(db, listingId.Value); OfferHelpers.CreateOfferForRequirement(db, User, requirementListing, offerQuantity.Value); } return(Json(new { success = true })); } else { return(Json(new { success = false })); } }
public ActionResult Edit([Bind(Include = "ListingId,ItemDescription,ItemType,QuantityRequired,QuantityFulfilled,QuantityOutstanding,UoM,RequiredFrom,RequiredTo,AcceptDamagedItems,AcceptOutOfDateItems,CollectionAvailable,ListingStatus,SelectedCampaignId,CampaignName,CampaignStrapLine,CampaignDescription,CampaignStartDateTime,CampaignEndDateTime")] RequirementListingEditView requirementListing) { if (ModelState.IsValid) { //If the 'Submit' button pressed then update tables, else leave as are so that on reload it takes original values once again. if (Request.Form["submitbutton"] != null) { //Update tables RequirementListingHelpers.UpdateRequirementListingFromRequirementListingEditView(db, requirementListing); return(RedirectToAction("Requirements", "ManageListings")); } return(RedirectToAction("Edit")); } //rebuild the missing details before returning to screen to show errors RequirementListing listing = RequirementListingHelpers.GetRequirementListing(db, requirementListing.ListingId); requirementListing.ListingAppUser = AppUserHelpers.GetAppUser(db, listing.ListingOriginatorAppUserId); requirementListing.ListingBranchDetails = BranchHelpers.GetBranch(db, listing.ListingOriginatorAppUserId); //Rebuild campaign details as changing will change ID but no address details, so force the change now: if (requirementListing.SelectedCampaignId != null) { Campaign campaign = CampaignHelpers.GetCampaign(db, requirementListing.SelectedCampaignId.Value); requirementListing.CampaignName = campaign.Name; requirementListing.CampaignStrapLine = campaign.StrapLine; requirementListing.CampaignDescription = campaign.Description; requirementListing.CampaignStartDateTime = campaign.CampaignStartDateTime; requirementListing.CampaignEndDateTime = campaign.CampaignEndDateTime; } ViewBag.CampaignList = ControlHelpers.AllActiveCampaignsForUserListDropDown(AppUserHelpers.GetAppUserIdFromUser(User), requirementListing.SelectedCampaignId); return(View(requirementListing)); }
public static RequirementListing UpdateRequirementListingFromRequirementListingEditView(ApplicationDbContext db, RequirementListingEditView view) { RequirementListing listing = GetRequirementListing(db, view.ListingId); listing.ItemDescription = view.ItemDescription; listing.ItemCategory = view.ItemCategory; listing.ItemType = view.ItemType; listing.QuantityRequired = view.QuantityRequired; listing.QuantityFulfilled = view.QuantityFulfilled; listing.QuantityOutstanding = view.QuantityOutstanding; listing.UoM = view.UoM; listing.RequiredFrom = view.RequiredFrom; listing.RequiredTo = view.RequiredTo; listing.AcceptDamagedItems = view.AcceptDamagedItems; listing.AcceptOutOfDateItems = view.AcceptOutOfDateItems; listing.CollectionAvailable = view.CollectionAvailable; listing.ListingStatus = view.ListingStatus; listing.CampaignId = view.SelectedCampaignId; db.Entry(listing).State = EntityState.Modified; db.SaveChanges(); return(listing); }
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); }
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); }
public static RequirementListingEditView GetRequirementListingEditView(ApplicationDbContext db, Guid listingId, IPrincipal user) { RequirementListing requirementListing = RequirementListingHelpers.GetRequirementListing(db, listingId); AppUser listingAppUser = AppUserHelpers.GetAppUser(db, requirementListing.ListingOriginatorAppUserId); Branch listingBranch = BranchHelpers.GetBranch(db, requirementListing.ListingOriginatorBranchId); Company listingCompany = CompanyHelpers.GetCompany(db, requirementListing.ListingOriginatorCompanyId); Campaign listingCampaign = null; Guid campaignId = Guid.Empty; string campaignName = ""; string campaignStrapline = ""; string campaignDescription = ""; DateTime?campaignStartDateTime = null; DateTime?campaignEndDateTime = null; ViewButtons buttons = ViewButtonsHelpers.GetAvailableButtonsForSingleView(db, listingAppUser, listingBranch, listingCompany, user); if (requirementListing.CampaignId != null) { if (requirementListing.CampaignId.Value != Guid.Empty) { listingCampaign = CampaignHelpers.GetCampaign(db, requirementListing.CampaignId.Value); campaignId = listingCampaign.CampaignId; campaignName = listingCampaign.Name; campaignStrapline = listingCampaign.StrapLine; campaignDescription = listingCampaign.Description; campaignStartDateTime = listingCampaign.CampaignStartDateTime; campaignEndDateTime = listingCampaign.CampaignEndDateTime; } } RequirementListingEditView view = new RequirementListingEditView() { ListingId = requirementListing.ListingId, ItemDescription = requirementListing.ItemDescription, ItemCategory = requirementListing.ItemCategory, ItemType = requirementListing.ItemType, QuantityRequired = requirementListing.QuantityRequired, QuantityFulfilled = requirementListing.QuantityFulfilled, QuantityOutstanding = requirementListing.QuantityOutstanding, UoM = requirementListing.UoM, RequiredFrom = requirementListing.RequiredFrom, RequiredTo = requirementListing.RequiredTo, AcceptDamagedItems = requirementListing.AcceptDamagedItems, AcceptOutOfDateItems = requirementListing.AcceptOutOfDateItems, CollectionAvailable = requirementListing.CollectionAvailable, ListingStatus = requirementListing.ListingStatus, ListingOriginatorDateTime = requirementListing.ListingOriginatorDateTime, ListingAppUser = listingAppUser, ListingBranchDetails = listingBranch, ListingCompanyDetails = listingCompany, SelectedCampaignId = campaignId, CampaignName = campaignName, CampaignStrapLine = campaignStrapline, CampaignDescription = campaignStrapline, CampaignStartDateTime = campaignStartDateTime, CampaignEndDateTime = campaignEndDateTime, Buttons = buttons }; return(view); }