public static OfferViewModel GetOfferViewModel(ApplicationDbContext db, HttpRequestBase request, Guid offerId, 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); } Offer offer = OfferHelpers.GetOffer(db, offerId); OfferViewModel model = new OfferViewModel() { DisplayOnly = displayOnly, Breadcrumb = breadcrumb, BreadcrumbDictionary = breadcrumbDictionary, Type = type, OfferId = offer.OfferId, ListingId = offer.ListingId, ListingType = offer.ListingType, OfferStatus = offer.OfferStatus, ItemDescription = offer.ItemDescription, QuantityOutstanding = OfferViewHelpers.GetListingQuantityForListingIdListingType(db, offer.ListingId, offer.ListingType), CurrentOfferQuantity = offer.CurrentOfferQuantity, PreviousOfferQuantity = offer.PreviousOfferQuantity, CounterOfferQuantity = offer.CounterOfferQuantity, PreviousCounterOfferQuantity = offer.PreviousCounterOfferQuantity, OfferOriginatorAppUser = AppUserHelpers.GetAppUserName(db, offer.OfferOriginatorAppUserId), OfferOriginatorOrganisation = OrganisationHelpers.GetOrganisationName(db, offer.OfferOriginatorOrganisationId), OfferOriginatorDateTime = offer.OfferOriginatorDateTime, YourOrganisationId = currentUser.OrganisationId, OfferOriginatorOrganisationId = offer.OfferOriginatorOrganisationId, RejectedBy = AppUserHelpers.GetAppUserName(db, offer.RejectedBy), RejectedOn = offer.RejectedOn, LastOfferOriginatorAppUser = AppUserHelpers.GetAppUserName(db, offer.LastOfferOriginatorAppUserId), LastOfferOriginatorDateTime = offer.LastOfferOriginatorDateTime, ListingOriginatorAppUser = AppUserHelpers.GetAppUserName(db, offer.ListingOriginatorAppUserId), ListingOriginatorOrganisation = OrganisationHelpers.GetOrganisationName(db, offer.ListingOriginatorOrganisationId), ListingOriginatorDateTime = offer.ListingOriginatorDateTime, CounterOfferOriginatorAppUser = AppUserHelpers.GetAppUserName(db, offer.CounterOfferOriginatorAppUserId), CounterOfferOriginatorOrganisation = OrganisationHelpers.GetOrganisationName(db, offer.CounterOfferOriginatorOrganisationId), CounterOfferOriginatorDateTime = offer.CounterOfferOriginatorDateTime, CounterOfferOriginatorOrganisationId = offer.CounterOfferOriginatorOrganisationId, LastCounterOfferOriginatorAppUser = AppUserHelpers.GetAppUserName(db, offer.LastCounterOfferOriginatorAppUserId), LastCounterOfferOriginatorDateTime = offer.LastCounterOfferOriginatorDateTime, OrderOriginatorAppUser = AppUserHelpers.GetAppUserName(db, offer.OrderOriginatorAppUserId), OrderOriginatorOrganisation = OrganisationHelpers.GetOrganisationName(db, offer.OrderOriginatorOrganisationId), OrderOriginatorDateTime = offer.OrderOriginatorDateTime, CallingAction = actionValue, CallingActionDisplayName = callingActionDisplayName, CallingController = controllerValue, BreadcrumbTrail = breadcrumbDictionary }; if (displayOnly) { model.EditableQuantity = false; } else { if (type == "created") { model.EditableQuantity = offer.CurrentOfferQuantity == 0; } else if (type == "received") { model.EditableQuantity = offer.CurrentOfferQuantity > 0; } } return(model); }