public static Company UpdateCompany(ApplicationDbContext db, Guid companyId, Guid headOfficeBranchId, string companyName, string companyRegistrationDetails, string charityRegistrationDetails, string vatRegistrationDetails, bool allowBranchTrading, PrivacyLevelEnum privacyLevel, EntityStatusEnum entityStatus) { Company company = CompanyHelpers.GetCompany(companyId); company.HeadOfficeBranchId = headOfficeBranchId; company.CompanyName = companyName; company.CompanyRegistrationDetails = companyRegistrationDetails; company.CharityRegistrationDetails = charityRegistrationDetails; company.VATRegistrationDetails = vatRegistrationDetails; company.AllowBranchTrading = allowBranchTrading; company.PrivacyLevel = privacyLevel; company.EntityStatus = entityStatus; db.Entry(company).State = EntityState.Modified; db.SaveChanges(); return(company); }
public static CampaignEditView GetCampaignEditView(ApplicationDbContext db, Guid campaignId, IPrincipal user) { Campaign campaignDetails = CampaignHelpers.GetCampaign(db, campaignId); AppUser campaignAppUser = AppUserHelpers.GetAppUser(db, campaignDetails.CampaignOriginatorAppUserId); Branch campaignBranch = BranchHelpers.GetBranch(db, campaignDetails.CampaignOriginatorBranchId); Company campaignCompany = CompanyHelpers.GetCompany(db, campaignDetails.CampaignOriginatorCompanyId); ViewButtons buttons = ViewButtonsHelpers.GetAvailableButtonsForSingleView(db, campaignAppUser, campaignBranch, campaignCompany, user); CampaignEditView view = new CampaignEditView() { CampaignId = campaignDetails.CampaignId, Name = campaignDetails.Name, StrapLine = campaignDetails.StrapLine, Description = campaignDetails.Description, Image = campaignDetails.Image, ImageLocation = campaignDetails.ImageLocation, Website = campaignDetails.Website, CampaignStartDateTime = campaignDetails.CampaignStartDateTime, CampaignEndDateTime = campaignDetails.CampaignEndDateTime, LocationName = campaignDetails.LocationName, LocationAddressLine1 = campaignDetails.LocationAddressLine1, LocationAddressLine2 = campaignDetails.LocationAddressLine2, LocationAddressLine3 = campaignDetails.LocationAddressLine3, LocationAddressTownCity = campaignDetails.LocationAddressTownCity, LocationAddressCounty = campaignDetails.LocationAddressCounty, LocationAddressPostcode = campaignDetails.LocationAddressPostcode, LocationTelephoneNumber = campaignDetails.LocationTelephoneNumber, LocationEmail = campaignDetails.LocationEmail, LocationContactName = campaignDetails.LocationContactName, EntityStatus = campaignDetails.EntityStatus, CampaignOriginatorDateTime = campaignDetails.CampaignOriginatorDateTime, CampaignAppUser = campaignAppUser, CampaignBranchDetails = campaignBranch, CampaignCompanyDetails = campaignCompany, Buttons = buttons }; return(view); }
public static AvailableListingEditView GetAvailableListingEditView(ApplicationDbContext db, Guid listingId, IPrincipal user) { AvailableListing availableListing = AvailableListingHelpers.GetAvailableListing(db, listingId); AppUser listingAppUser = AppUserHelpers.GetAppUser(db, availableListing.ListingOriginatorAppUserId); Branch listingBranch = BranchHelpers.GetBranch(db, availableListing.ListingOriginatorBranchId); Company listingCompany = CompanyHelpers.GetCompany(db, availableListing.ListingOriginatorCompanyId); ViewButtons buttons = ViewButtonsHelpers.GetAvailableButtonsForSingleView(db, listingAppUser, listingBranch, listingCompany, user); AvailableListingEditView view = new AvailableListingEditView() { ListingId = availableListing.ListingId, ItemDescription = availableListing.ItemDescription, ItemCategory = availableListing.ItemCategory, ItemType = availableListing.ItemType, QuantityRequired = availableListing.QuantityRequired, QuantityFulfilled = availableListing.QuantityFulfilled, QuantityOutstanding = availableListing.QuantityOutstanding, UoM = availableListing.UoM, AvailableFrom = availableListing.AvailableFrom, AvailableTo = availableListing.AvailableTo, ItemCondition = availableListing.ItemCondition, DisplayUntilDate = availableListing.DisplayUntilDate, SellByDate = availableListing.SellByDate, UseByDate = availableListing.UseByDate, DeliveryAvailable = availableListing.DeliveryAvailable, ListingStatus = availableListing.ListingStatus, ListingOriginatorDateTime = availableListing.ListingOriginatorDateTime, ListingAppUser = listingAppUser, ListingBranchDetails = listingBranch, ListingCompanyDetails = listingCompany, Buttons = buttons }; 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 List <AvailableListingGeneralInfoView> GetAllAvailableListingsGeneralInfoView(ApplicationDbContext db, IPrincipal user) { List <AvailableListingGeneralInfoView> allAvailableListingsGeneralInfoView = new List <AvailableListingGeneralInfoView>(); AppUser appUser = AppUserHelpers.GetAppUser(db, user); AppUserSettings settings = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, appUser.AppUserId); Branch currentBranch = BranchHelpers.GetBranch(appUser.CurrentBranchId); List <AvailableListing> allAvailableListings = AvailableListingHelpers.GetAllGeneralInfoFilteredAvailableListings(db, appUser.AppUserId); foreach (AvailableListing availableListing in allAvailableListings) { //Find any related offers Offer offer = OfferHelpers.GetOfferForListingAndUser(db, availableListing.ListingId, appUser.AppUserId); decimal offerQty = 0M; if (offer != null) { offerQty = offer.CurrentOfferQuantity; } bool userBlocked = false; bool branchBlocked = false; bool companyBlocked = false; BlockHelpers.GetBlocksForAllTypesForSpecificOfBy(db, availableListing.ListingOriginatorAppUserId, appUser.AppUserId, availableListing.ListingOriginatorBranchId, currentBranch.BranchId, availableListing.ListingOriginatorCompanyId, currentBranch.CompanyId, out userBlocked, out branchBlocked, out companyBlocked); bool userMatchedOwner = false; bool branchMatchedOwner = false; bool companyMatchedOwner = false; if (currentBranch.CompanyId == availableListing.ListingOriginatorCompanyId) { companyMatchedOwner = true; } if (currentBranch.BranchId == availableListing.ListingOriginatorBranchId) { branchMatchedOwner = true; } if (appUser.AppUserId == availableListing.ListingOriginatorAppUserId) { userMatchedOwner = true; } Company company = CompanyHelpers.GetCompany(db, availableListing.ListingOriginatorCompanyId); AvailableListingGeneralInfoView AvailableListingGeneralInfoView = new AvailableListingGeneralInfoView() { AvailableListing = availableListing, OfferQuantity = offerQty, AllowBranchTrading = company.AllowBranchTrading, UserLevelBlock = userBlocked, BranchLevelBlock = branchBlocked, CompanyLevelBlock = companyBlocked, DisplayBlocks = settings.AvailableListingGeneralInfoDisplayBlockedListings, CompanyLevelOwner = companyMatchedOwner, DisplayMyCompanyRecords = settings.AvailableListingGeneralInfoDisplayMyUserListings, BranchLevelOwner = branchMatchedOwner, DisplayMyBranchRecords = settings.AvailableListingGeneralInfoDisplayMyBranchListings, UserLevelOwner = userMatchedOwner, DisplayMyRecords = settings.AvailableListingGeneralInfoDisplayMyUserListings }; allAvailableListingsGeneralInfoView.Add(AvailableListingGeneralInfoView); } return(allAvailableListingsGeneralInfoView); }
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); }