public static RequiredListing UpdateRequiredListingQuantities(ApplicationDbContext db, Guid listingId, ListingQuantityChange changeOfValue, decimal changeQty, IPrincipal user) { RequiredListing listing = RequiredListingHelpers.GetRequiredListing(db, listingId); listing.RecordChange = RecordChangeEnum.RecordUpdated; listing.RecordChangeBy = AppUserHelpers.GetAppUserIdFromUser(user); listing.RecordChangeOn = DateTime.Now; if (changeOfValue == ListingQuantityChange.Subtract) { listing.QuantityFulfilled += changeQty; listing.QuantityOutstanding -= changeQty; if (listing.QuantityOutstanding == 0) { listing.ListingStatus = ItemRequiredListingStatusEnum.Complete; listing.RecordChange = RecordChangeEnum.ListingStatusChange; } } else { listing.QuantityFulfilled -= changeQty; listing.QuantityOutstanding += changeQty; } db.Entry(listing).State = EntityState.Modified; db.SaveChanges(); return(listing); }
public static Offer CreateOffer(ApplicationDbContext db, Guid listingId, decimal?offerQty, ListingTypeEnum listingType, AppUser currentUser, IPrincipal user) { if (currentUser == null) { currentUser = AppUserHelpers.GetAppUser(db, user); } Guid listingOrigAppUserId = Guid.Empty; Guid listingOrigOrgId = Guid.Empty; DateTime listingOrigDateTime = DateTime.MinValue; string itemDescription = ""; //Get originator information for the correct listing if (listingType == ListingTypeEnum.Available) { AvailableListing availableListing = AvailableListingHelpers.GetAvailableListing(db, listingId); listingOrigAppUserId = availableListing.ListingOriginatorAppUserId; listingOrigOrgId = availableListing.ListingOriginatorOrganisationId; listingOrigDateTime = availableListing.ListingOriginatorDateTime; itemDescription = availableListing.ItemDescription; } else { RequiredListing requiredListing = RequiredListingHelpers.GetRequiredListing(db, listingId); listingOrigAppUserId = requiredListing.ListingOriginatorAppUserId; listingOrigOrgId = requiredListing.ListingOriginatorOrganisationId; listingOrigDateTime = requiredListing.ListingOriginatorDateTime; itemDescription = requiredListing.ItemDescription; } //create offer Offer offer = new Offer() { OfferId = Guid.NewGuid(), ListingId = listingId, ListingType = listingType, OfferStatus = OfferStatusEnum.New, ItemDescription = itemDescription, CurrentOfferQuantity = offerQty.Value, OfferOriginatorAppUserId = currentUser.AppUserId, OfferOriginatorOrganisationId = currentUser.OrganisationId, OfferOriginatorDateTime = DateTime.Now, ListingOriginatorAppUserId = listingOrigAppUserId, ListingOriginatorOrganisationId = listingOrigOrgId, ListingOriginatorDateTime = listingOrigDateTime }; db.Offers.Add(offer); db.SaveChanges(); //Create Action Organisation org = OrganisationHelpers.GetOrganisation(db, currentUser.OrganisationId); NotificationHelpers.CreateNotification(db, NotificationTypeEnum.NewOfferReceived, "New offer received from " + org.OrganisationName, offer.OfferId, listingOrigAppUserId, listingOrigOrgId, user); return(offer); }
//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 decimal GetListingQuantityForListingIdListingType(ApplicationDbContext db, Guid listingId, ListingTypeEnum listingType) { decimal quantityOutstanding = 0.00M; switch (listingType) { case ListingTypeEnum.Available: quantityOutstanding = AvailableListingHelpers.GetAvailableListing(db, listingId).QuantityOutstanding; break; case ListingTypeEnum.Requirement: quantityOutstanding = RequiredListingHelpers.GetRequiredListing(db, listingId).QuantityOutstanding; break; } return(quantityOutstanding); }
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 RequiredListingDetailsViewModel CreateRequiredListingDetailsViewModel(ApplicationDbContext db, Guid listingId, string breadcrumb, bool displayOnly, HttpRequestBase request, string controllerValue, string actionValue, string callingActionDisplayName, Dictionary <int, string> breadcrumbDictionary, bool?recalled, IPrincipal user, int?maxDistance, double?maxAge) { RequiredListing listing = RequiredListingHelpers.GetRequiredListing(db, listingId); if (listing != null) { //Set up the calling fields if (!recalled.HasValue) { GeneralHelpers.GetCallingDetailsFromRequest(request, controllerValue, actionValue, out controllerValue, out actionValue); } AppUser recordChangedBy = AppUserHelpers.GetAppUser(db, listing.RecordChangeBy); AppUser listingOriginatorAppUser = AppUserHelpers.GetAppUser(db, listing.ListingOriginatorAppUserId); RequiredListingDetailsViewModel model = new RequiredListingDetailsViewModel() { Breadcrumb = breadcrumb, DisplayOnly = displayOnly, ListingId = listing.ListingId, ItemDescription = listing.ItemDescription, ItemCategory = listing.ItemCategory, ItemType = listing.ItemType, QuantityRequired = listing.QuantityRequired, QuantityFulfilled = listing.QuantityFulfilled, QuantityOutstanding = listing.QuantityOutstanding, UoM = listing.UoM, RequiredFrom = listing.RequiredFrom, RequiredTo = listing.RequiredTo, AcceptDamagedItems = listing.AcceptDamagedItems, AcceptOutOfDateItems = listing.AcceptOutOfDateItems, CollectionAvailable = listing.CollectionAvailable, ListingStatus = listing.ListingStatus, ListingOrganisationPostcode = listing.ListingOrganisationPostcode, RecordChange = listing.RecordChange, RecordChangeOn = listing.RecordChangeOn, RecordChangeByName = recordChangedBy.FirstName + " " + recordChangedBy.LastName, RecordChangeByEmail = recordChangedBy.LoginEmail, ListingOriginatorAppUserName = listingOriginatorAppUser.FirstName + " " + listingOriginatorAppUser.LastName, ListingOriginatorAppUserEmail = listingOriginatorAppUser.LoginEmail, ListingOriginatorDateTime = listing.ListingOriginatorDateTime, CallingController = controllerValue, CallingAction = actionValue, CallingActionDisplayName = callingActionDisplayName, BreadcrumbTrail = breadcrumbDictionary }; if (controllerValue == "GeneralInfo" && actionValue == "Required") { //Get user info for the offer side of the display AppUser currentUser = AppUserHelpers.GetAppUser(db, user); Organisation currentOrg = OrganisationHelpers.GetOrganisation(db, currentUser.OrganisationId); Offer offer = OfferHelpers.GetOfferForListingByUser(db, listing.ListingId, currentUser.AppUserId, currentOrg.OrganisationId, currentOrg.ListingPrivacyLevel); if (offer == null) { model.OfferDescription = "Make a request"; } else { model.OfferDescription = "Current request"; model.OfferId = offer.OfferId; model.OfferQty = offer.CurrentOfferQuantity; model.OfferCounterQty = offer.CounterOfferQuantity; model.OfferStatus = offer.OfferStatus; } } return(model); } else { return(null); } }