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 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); }
public static DashboardView GetDashboardView(ApplicationDbContext db) { //initialise the view DashboardView dashboardView = new DashboardView(); //get the campaigns and listings for this user List <Campaign> campaigns = CampaignHelpers.GetAllCampaigns(db); dashboardView.CampaignList = campaigns; List <RequirementListing> requirementListings = RequirementListingHelpers.GetAllRequirementListings(db); dashboardView.RequirementListingList = requirementListings; return(dashboardView); }
public static List <RequirementListingManageView> GetAllRequirementListingsManageView(ApplicationDbContext db, IPrincipal user, bool getHistory) { List <RequirementListingManageView> allRequirementListingsManageView = new List <RequirementListingManageView>(); AppUser appUser = AppUserHelpers.GetAppUser(db, user); List <RequirementListing> allRequirementListingsForUser = RequirementListingHelpers.GetAllManageListingFilteredRequirementListings(db, appUser.AppUserId, getHistory); foreach (RequirementListing requirementListingForBranchUser in allRequirementListingsForUser) { RequirementListingManageView requirementListingManageView = new RequirementListingManageView() { RequirementListing = requirementListingForBranchUser }; allRequirementListingsManageView.Add(requirementListingManageView); } return(allRequirementListingsManageView); }
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 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); }
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); }
public static List <RequirementListingGeneralInfoView> GetAllRequirementListingsGeneralInfoView(ApplicationDbContext db, IPrincipal user) { List <RequirementListingGeneralInfoView> allRequirementListingsGeneralInfoView = new List <RequirementListingGeneralInfoView>(); AppUser appUser = AppUserHelpers.GetAppUser(db, user); AppUserSettings settings = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, appUser.AppUserId); Branch currentBranch = BranchHelpers.GetBranch(appUser.CurrentBranchId); List <RequirementListing> allRequirementListings = RequirementListingHelpers.GetAllGeneralInfoFilteredRequirementListings(db, appUser.AppUserId); foreach (RequirementListing requirementListing in allRequirementListings) { //Find any related offers Offer offer = OfferHelpers.GetOfferForListingAndUser(db, requirementListing.ListingId, appUser.AppUserId); decimal offerQty = 0M; if (offer != null) { offerQty = offer.CurrentOfferQuantity; } bool userBlocked = false; bool branchBlocked = false; bool companyBlocked = false; BlockHelpers.GetBlocksForAllTypesForSpecificOfBy(db, requirementListing.ListingOriginatorAppUserId, appUser.AppUserId, requirementListing.ListingOriginatorBranchId, currentBranch.BranchId, requirementListing.ListingOriginatorCompanyId, currentBranch.CompanyId, out userBlocked, out branchBlocked, out companyBlocked); bool userMatchedOwner = false; bool branchMatchedOwner = false; bool companyMatchedOwner = false; if (currentBranch.CompanyId == requirementListing.ListingOriginatorCompanyId) { companyMatchedOwner = true; } if (currentBranch.BranchId == requirementListing.ListingOriginatorBranchId) { branchMatchedOwner = true; } if (appUser.AppUserId == requirementListing.ListingOriginatorAppUserId) { userMatchedOwner = true; } Company company = CompanyHelpers.GetCompany(db, requirementListing.ListingOriginatorCompanyId); RequirementListingGeneralInfoView requirementListingGeneralInfoView = new RequirementListingGeneralInfoView() { RequirementListing = requirementListing, OfferQuantity = offerQty, AllowBranchTrading = company.AllowBranchTrading, UserLevelBlock = userBlocked, BranchLevelBlock = branchBlocked, CompanyLevelBlock = companyBlocked, DisplayBlocks = settings.RequiredListingGeneralInfoDisplayBlockedListings, CompanyLevelOwner = companyMatchedOwner, DisplayMyCompanyRecords = settings.RequiredListingGeneralInfoDisplayMyCompanyListings, BranchLevelOwner = branchMatchedOwner, DisplayMyBranchRecords = settings.RequiredListingGeneralInfoDisplayMyBranchListings, UserLevelOwner = userMatchedOwner, DisplayMyRecords = settings.RequiredListingGeneralInfoDisplayMyUserListings }; allRequirementListingsGeneralInfoView.Add(requirementListingGeneralInfoView); } return(allRequirementListingsGeneralInfoView); }