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); }
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); }
//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); }
public static Offer AcceptOffer(ApplicationDbContext db, IPrincipal user, Offer offer) { offer.OfferStatus = OfferStatusEnum.Accepted; Order order = OrderHelpers.CreateOrder(db, user, offer); offer.OrderId = order.OrderId; offer.OrderOriginatorAppUserId = order.OrderOriginatorAppUserId; offer.OrderOriginatorBranchId = order.OrderOriginatorBranchId; offer.OrderOriginatorCompanyId = order.OrderOriginatorCompanyId; offer.OrderOriginatorDateTime = order.OrderOriginatorDateTime; db.Entry(offer).State = EntityState.Modified; db.SaveChanges(); return(offer); }
public static List <OrderManageView> GetAllOrdersManageViewForUser(ApplicationDbContext db, IPrincipal user) { List <OrderManageView> allOrdersManageView = new List <OrderManageView>(); AppUser appUser = AppUserHelpers.GetAppUser(db, user); List <Order> allOrdersForUser = OrderHelpers.GetAllOrdersForUser(db, appUser.AppUserId, false); foreach (Order orderForUser in allOrdersForUser) { OrderManageView orderManageView = new OrderManageView() { OrderDetails = orderForUser }; allOrdersManageView.Add(orderManageView); } return(allOrdersManageView); }
public static List <OrderManageView> GetAllOrdersManageView(ApplicationDbContext db, IPrincipal user, bool getHistory) { List <OrderManageView> allOrdersManageView = new List <OrderManageView>(); AppUser appUser = AppUserHelpers.GetAppUser(db, user); List <Order> allOrdersForUser = OrderHelpers.GetAllManageListingFilteredOrders(db, appUser.AppUserId, getHistory); //If we allow branch trading then differentiate between branches for in/out trading, otherwise it is at company level Company company = CompanyHelpers.GetCompanyForUser(db, user); foreach (Order orderForBranchUser in allOrdersForUser) { OrderManageView orderManageView = new OrderManageView(); orderManageView.OrderDetails = orderForBranchUser; //set Inhouse flag orderManageView.InhouseOrder = OrderProcessHelpers.SetInhouseFlag(orderForBranchUser, appUser, company); //Set OrderOut flag orderManageView.OrderOut = OrderProcessHelpers.SetOrderOutFlag(orderForBranchUser, orderManageView.InhouseOrder); //set buttons bool?displayDespatchButton = null; bool?displayDeliveredButton = null; bool?displayReceivedButton = null; bool?displayCollectedButton = null; bool?displayClosedButton = null; OrderProcessHelpers.SetOrderButtons(db, user, orderForBranchUser, orderManageView.OrderOut, out displayDespatchButton, out displayDeliveredButton, out displayReceivedButton, out displayCollectedButton, out displayClosedButton); orderManageView.DisplayDespatchButton = displayDespatchButton; orderManageView.DisplayDeliveredButton = displayDeliveredButton; orderManageView.DisplayReceivedButton = displayReceivedButton; orderManageView.DisplayCollectedButton = displayCollectedButton; orderManageView.DisplayClosedButton = displayClosedButton; allOrdersManageView.Add(orderManageView); } return(allOrdersManageView); }
public static HomeDashboardView CreateHomeDashboardView(ApplicationDbContext db, IPrincipal user) { HomeDashboardView view = new HomeDashboardView(); Organisation currentOrg = OrganisationHelpers.GetOrganisation(db, AppUserHelpers.GetOrganisationIdFromUser(db, user)); DateTime weekAgo = DateTime.Now.AddDays(-7); DateTime dayAgo = DateTime.Now.AddDays(-1); List <Notification> openNotifications = NotificationHelpers.GetNotificationsForOrganisationFromUser(db, user, false); view.OpenNotifications = openNotifications.Count; view.OpenNotificationsThisWeek = (from oN in openNotifications where oN.RecordChangeOn >= weekAgo select oN).Count(); if (view.OpenNotificationsThisWeek == 0) { view.OpenNotificationsThisWeekPercent = 0; } else { view.OpenNotificationsThisWeekPercent = (Convert.ToDecimal(view.OpenNotificationsThisWeek) / Convert.ToDecimal(view.OpenNotifications)) * 100; } view.OpenNotificationsPastDay = (from oN in openNotifications where oN.RecordChangeOn >= dayAgo select oN).Count(); if (view.OpenNotificationsPastDay == 0) { view.OpenNotificationsPastDayPercent = 0; } else { view.OpenNotificationsPastDayPercent = (Convert.ToDecimal(view.OpenNotificationsPastDay) / Convert.ToDecimal(view.OpenNotifications)) * 100; } List <UserTask> openUserTasks = UserTasksHelpers.GetUserTasksForOrganisationFromUser(db, user, false); view.OpenTasks = openUserTasks.Count; view.OpenTasksThisWeek = (from oT in openUserTasks where oT.RecordChangeOn >= weekAgo select oT).Count(); if (view.OpenTasksThisWeek == 0) { view.OpenTasksThisWeekPercent = 0; } else { view.OpenTasksThisWeekPercent = (Convert.ToDecimal(view.OpenTasksThisWeek) / Convert.ToDecimal(view.OpenTasks)) * 100; } view.OpenTasksPastDay = (from oT in openUserTasks where oT.RecordChangeOn >= dayAgo select oT).Count(); if (view.OpenTasksPastDay == 0) { view.OpenTasksPastDayPercent = 0; } else { view.OpenTasksPastDayPercent = (Convert.ToDecimal(view.OpenTasksPastDay) / Convert.ToDecimal(view.OpenTasks)) * 100; } List <Offer> offersCreated = OfferHelpers.GetOpenOffersCreatedForOrganisation(db, currentOrg.OrganisationId); view.OffersCreatedOpen = offersCreated.Count; view.OffersCreatedCountered = (from oC in offersCreated where oC.OfferStatus == OfferStatusEnum.Countered select oC).Count(); if (view.OffersCreatedCountered == 0) { view.OffersCreatedCounteredPercent = 0; } else { view.OffersCreatedCounteredPercent = (Convert.ToDecimal(view.OffersCreatedCountered) / Convert.ToDecimal(view.OffersCreatedOpen)) * 100; } view.OffersCreatedReOffered = (from oC in offersCreated where oC.OfferStatus == OfferStatusEnum.Reoffer select oC).Count(); if (view.OffersCreatedReOffered == 0) { view.OffersCreatedReOfferedPercent = 0; } else { view.OffersCreatedReOfferedPercent = (Convert.ToDecimal(view.OffersCreatedReOffered) / Convert.ToDecimal(view.OffersCreatedOpen)) * 100; } List <Offer> offersCreatedClosed = OfferHelpers.GetAllOffersCreatedClosedForWeekForOrganisation(db, currentOrg.OrganisationId); view.OffersCreatedAcceptedThisWeek = (from oCC in offersCreatedClosed where oCC.OfferStatus == OfferStatusEnum.Accepted select oCC).Count(); view.OffersCreatedRejectedThisWeek = (from oCC in offersCreatedClosed where oCC.OfferStatus == OfferStatusEnum.Rejected select oCC).Count(); view.OffersCreatedClosedThisWeek = (from oCC in offersCreatedClosed where oCC.OfferStatus == OfferStatusEnum.ClosedNoStock select oCC).Count(); view.OffersCreatedClosedTotalThisWeek = view.OffersCreatedAcceptedThisWeek + view.OffersCreatedRejectedThisWeek + view.OffersCreatedClosedThisWeek; if (view.OffersCreatedAcceptedThisWeek == 0) { view.OffersCreatedAcceptedThisWeekPercent = 0; } else { view.OffersCreatedAcceptedThisWeekPercent = (Convert.ToDecimal(view.OffersCreatedAcceptedThisWeek) / Convert.ToDecimal(view.OffersCreatedClosedTotalThisWeek)) * 100; } if (view.OffersCreatedRejectedThisWeek == 0) { view.OffersCreatedRejectedThisWeekPercent = 0; } else { view.OffersCreatedRejectedThisWeekPercent = (Convert.ToDecimal(view.OffersCreatedRejectedThisWeek) / Convert.ToDecimal(view.OffersCreatedClosedTotalThisWeek)) * 100; } if (view.OffersCreatedClosedThisWeek == 0) { view.OffersCreatedClosedThisWeekPercent = 0; } else { view.OffersCreatedClosedThisWeekPercent = (Convert.ToDecimal(view.OffersCreatedClosedThisWeek) / Convert.ToDecimal(view.OffersCreatedClosedTotalThisWeek)) * 100; } List <Offer> offersReceived = OfferHelpers.GetOpenOffersReceivedForOrganisation(db, currentOrg.OrganisationId); view.OffersReceivedOpen = offersReceived.Count; view.OffersReceivedCountered = (from oR in offersReceived where oR.OfferStatus == OfferStatusEnum.Countered select oR).Count(); if (view.OffersReceivedCountered == 0) { view.OffersReceivedCounteredPercent = 0; } else { view.OffersReceivedCounteredPercent = (Convert.ToDecimal(view.OffersReceivedCountered) / Convert.ToDecimal(view.OffersReceivedOpen)) * 100; } view.OffersReceivedReOffered = (from oR in offersReceived where oR.OfferStatus == OfferStatusEnum.Reoffer select oR).Count(); if (view.OffersReceivedReOffered == 0) { view.OffersReceivedReOfferedPercent = 0; } else { view.OffersReceivedReOfferedPercent = (Convert.ToDecimal(view.OffersReceivedReOffered) / Convert.ToDecimal(view.OffersReceivedOpen)) * 100; } List <Offer> offersReceivedClosed = OfferHelpers.GetAllOffersReceivedClosedForWeekForOrganisation(db, currentOrg.OrganisationId); view.OffersReceivedAcceptedThisWeek = (from oRC in offersReceived where oRC.OfferStatus == OfferStatusEnum.Accepted select oRC).Count(); view.OffersReceivedRejectedThisWeek = (from oRC in offersReceived where oRC.OfferStatus == OfferStatusEnum.Rejected select oRC).Count(); view.OffersReceivedClosedThisWeek = (from oRC in offersReceived where oRC.OfferStatus == OfferStatusEnum.ClosedNoStock select oRC).Count(); view.OffersReceivedClosedTotalThisWeek = view.OffersReceivedAcceptedThisWeek + view.OffersReceivedRejectedThisWeek + view.OffersReceivedClosedThisWeek; if (view.OffersReceivedAcceptedThisWeek == 0) { view.OffersReceivedAcceptedThisWeekPercent = 0; } else { view.OffersReceivedAcceptedThisWeekPercent = (Convert.ToDecimal(view.OffersReceivedAcceptedThisWeek) / Convert.ToDecimal(view.OffersReceivedClosedTotalThisWeek)) * 100; } if (view.OffersReceivedRejectedThisWeek == 0) { view.OffersReceivedRejectedThisWeekPercent = 0; } else { view.OffersReceivedRejectedThisWeekPercent = (Convert.ToDecimal(view.OffersReceivedRejectedThisWeek) / Convert.ToDecimal(view.OffersReceivedClosedTotalThisWeek)) * 100; } if (view.OffersReceivedClosedThisWeek == 0) { view.OffersReceivedClosedThisWeekPercent = 0; } else { view.OffersReceivedClosedThisWeekPercent = (Convert.ToDecimal(view.OffersReceivedClosedThisWeek) / Convert.ToDecimal(view.OffersReceivedClosedTotalThisWeek)) * 100; } view.OrdersInOpen = OrderHelpers.GetOrdersInForOganisationCount(db, currentOrg.OrganisationId); List <Order> ordersIn = OrderHelpers.GetOrdersInForWeekForOrganisation(db, currentOrg.OrganisationId); view.OrdersInCollectedThisWeek = (from oI in ordersIn where oI.OrderInStatus == OrderInStatusEnum.Collected select oI).Count(); view.OrdersInReceivedThisWeek = (from oI in ordersIn where oI.OrderInStatus == OrderInStatusEnum.Received select oI).Count(); view.OrdersInClosedThisWeek = (from oI in ordersIn where oI.OrderInStatus == OrderInStatusEnum.Closed select oI).Count(); int ordersInClosedCount = view.OrdersInCollectedThisWeek + view.OrdersInReceivedThisWeek + view.OrdersInClosedThisWeek; if (view.OrdersInCollectedThisWeek == 0) { view.OrdersInCollectedThisWeekPercent = 0; } else { view.OrdersInCollectedThisWeekPercent = (Convert.ToDecimal(view.OrdersInCollectedThisWeek) / Convert.ToDecimal(ordersInClosedCount)) * 100; } if (view.OrdersInReceivedThisWeek == 0) { view.OrdersInReceivedThisWeekPercent = 0; } else { view.OrdersInReceivedThisWeekPercent = (Convert.ToDecimal(view.OrdersInReceivedThisWeek) / Convert.ToDecimal(ordersInClosedCount)) * 100; } if (view.OrdersInClosedThisWeek == 0) { view.OrdersInClosedThisWeekPercent = 0; } else { view.OrdersInClosedThisWeekPercent = (Convert.ToDecimal(view.OrdersInClosedThisWeek) / Convert.ToDecimal(ordersInClosedCount)) * 100; } view.OrdersOutOpen = OrderHelpers.GetOrdersOutForOganisationCount(db, currentOrg.OrganisationId); List <Order> ordersOut = OrderHelpers.GetOrdersOutForWeekForOganisation(db, currentOrg.OrganisationId); view.OrdersOutDespatchedThisWeek = (from oO in ordersOut where oO.OrderOutStatus == OrderOutStatusEnum.Dispatched select oO).Count(); view.OrdersOutDeliveredThisWeek = (from oO in ordersOut where oO.OrderOutStatus == OrderOutStatusEnum.Delivered select oO).Count(); view.OrdersOutClosedThisWeek = (from oO in ordersOut where oO.OrderOutStatus == OrderOutStatusEnum.Closed select oO).Count(); int ordersOutClosedCount = view.OrdersOutDespatchedThisWeek + view.OrdersOutDeliveredThisWeek + view.OrdersOutClosedThisWeek; if (view.OrdersOutDespatchedThisWeek == 0) { view.OrdersOutDespatchedThisWeekPercent = 0; } else { view.OrdersOutDespatchedThisWeekPercent = (Convert.ToDecimal(view.OrdersOutDespatchedThisWeek) / Convert.ToDecimal(ordersOutClosedCount)) * 100; } if (view.OrdersOutDeliveredThisWeek == 0) { view.OrdersOutDeliveredThisWeekPercent = 0; } else { view.OrdersOutDeliveredThisWeekPercent = (Convert.ToDecimal(view.OrdersOutDeliveredThisWeek) / Convert.ToDecimal(ordersOutClosedCount)) * 100; } if (view.OrdersOutClosedThisWeek == 0) { view.OrdersOutClosedThisWeekPercent = 0; } else { view.OrdersOutClosedThisWeekPercent = (Convert.ToDecimal(view.OrdersOutClosedThisWeek) / Convert.ToDecimal(ordersOutClosedCount)) * 100; } return(view); }
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 OrderViewModel GetOfferViewModel(ApplicationDbContext db, HttpRequestBase request, Guid orderId, 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); } Order order = OrderHelpers.GetOrder(db, orderId); string itemDescription = ""; ItemTypeEnum itemType = ItemTypeEnum.Canned; string uoM = ""; if (order.ListingType == ListingTypeEnum.Available) { AvailableListing listing = AvailableListingHelpers.GetAvailableListing(db, order.ListingId.Value); itemDescription = listing.ItemDescription; itemType = listing.ItemType; uoM = listing.UoM; } else { RequiredListing listing = RequiredListingHelpers.GetRequiredListing(db, order.ListingId.Value); itemDescription = listing.ItemDescription; itemType = listing.ItemType; uoM = listing.UoM; } OrderViewModel model = new OrderViewModel() { DisplayOnly = displayOnly, Breadcrumb = breadcrumb, BreadcrumbDictionary = breadcrumbDictionary, Type = type, OrderId = order.OrderId, ListingType = order.ListingType, ItemDescription = itemDescription, ItemType = itemType, UoM = uoM, OrderQuanity = order.OrderQuanity, OrderInStatus = order.OrderInStatus, OrderOutStatus = order.OrderOutStatus, OrderCreationDateTime = order.OrderCreationDateTime, OrderDistributionDateTime = order.OrderDistributionDateTime, OrderDistributedBy = AppUserHelpers.GetAppUserName(db, order.OrderDistributedBy), OrderDeliveredDateTime = order.OrderDeliveredDateTime, OrderDeliveredBy = AppUserHelpers.GetAppUserName(db, order.OrderDeliveredBy), OrderCollectedDateTime = order.OrderCollectedDateTime, OrderCollectedBy = AppUserHelpers.GetAppUserName(db, order.OrderCollectedBy), OrderReceivedDateTime = order.OrderReceivedDateTime, OrderReceivedBy = AppUserHelpers.GetAppUserName(db, order.OrderReceivedBy), OrderInClosedDateTime = order.OrderInClosedDateTime, OrderInClosedBy = AppUserHelpers.GetAppUserName(db, order.OrderInClosedBy), OrderOutClosedDateTime = order.OrderOutClosedDateTime, OrderOutClosedBy = AppUserHelpers.GetAppUserName(db, order.OrderOutClosedBy), OrderOriginatorAppUser = AppUserHelpers.GetAppUserName(db, order.OrderOriginatorAppUserId), OrderOriginatorOrganisation = OrganisationHelpers.GetOrganisationName(db, order.OrderOriginatorOrganisationId), OrderOriginatorDateTime = order.OrderOriginatorDateTime, OfferId = order.OfferId, OfferOriginatorAppUser = AppUserHelpers.GetAppUserName(db, order.OfferOriginatorAppUserId), OfferOriginatorOrganisation = OrganisationHelpers.GetOrganisationName(db, order.OfferOriginatorOrganisationId), ListingId = order.ListingId, ListingOriginatorAppUser = AppUserHelpers.GetAppUserName(db, order.ListingOriginatorAppUserId), ListingOriginatorOrganisation = OrganisationHelpers.GetOrganisationName(db, order.ListingOriginatorOrganisationId), CallingAction = actionValue, CallingActionDisplayName = callingActionDisplayName, CallingController = controllerValue, BreadcrumbTrail = breadcrumbDictionary }; return(model); }
public static Order UpdateOrderDates(ApplicationDbContext db, string type, Guid orderId, bool orderCollected, bool orderReceived, bool orderInClosed, bool orderDistributed, bool orderDelivered, bool orderOutClosed, IPrincipal user) { Order order = OrderHelpers.GetOrder(db, orderId); Guid currentAppUserId = AppUserHelpers.GetAppUserIdFromUser(user); if (type == "in") { if (orderCollected) { order.OrderCollectedBy = currentAppUserId; order.OrderCollectedDateTime = DateTime.Now; order.OrderInStatus = OrderInStatusEnum.Collected; } if (orderReceived) { order.OrderReceivedBy = currentAppUserId; order.OrderReceivedDateTime = DateTime.Now; order.OrderInStatus = OrderInStatusEnum.Received; } if (orderInClosed) { order.OrderInClosedBy = currentAppUserId; order.OrderInClosedDateTime = DateTime.Now; order.OrderInStatus = OrderInStatusEnum.Closed; } db.Entry(order).State = EntityState.Modified; db.SaveChanges(); //If order closed then add Action to Organisation of order out if they haven't closed their side yet saying this is closed //LSLSLS //Organisation org = OrganisationHelpers.GetOrganisation(db, offer.OfferOriginatorOrganisationId); //UserActionHelpers.CreateUserAction(db, ActionTypeEnum.NewOrderReceived, "New order received from " + org.OrganisationName, offer.OfferId, appUser.AppUserId, org.OrganisationId, user); } if (type == "out") { if (orderDistributed) { order.OrderDistributedBy = currentAppUserId; order.OrderDistributionDateTime = DateTime.Now; order.OrderOutStatus = OrderOutStatusEnum.Dispatched; } if (orderDelivered) { order.OrderDeliveredBy = currentAppUserId; order.OrderDeliveredDateTime = DateTime.Now; order.OrderOutStatus = OrderOutStatusEnum.Delivered; } if (orderOutClosed) { order.OrderOutClosedBy = currentAppUserId; order.OrderOutClosedDateTime = DateTime.Now; order.OrderOutStatus = OrderOutStatusEnum.Closed; } db.Entry(order).State = EntityState.Modified; db.SaveChanges(); //If order closed then add Action to Organisation of order out if they haven't closed their side yet saying this is closed //LSLSLS } return(order); }