//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 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); }