public static OfferManageView GetOfferManageViewForOffer(ApplicationDbContext db, Offer offer, IPrincipal user) { AppUser offerAppUser = AppUserHelpers.GetAppUser(db, offer.OfferOriginatorAppUserId); AvailableListing availableListing = null; RequirementListing requirementListing = null; AppUser listingAppUser = null; switch (offer.ListingType) { case ListingTypeEnum.Available: availableListing = AvailableListingHelpers.GetAvailableListing(db, offer.ListingId); listingAppUser = AppUserHelpers.GetAppUser(db, availableListing.ListingOriginatorAppUserId); break; case ListingTypeEnum.Requirement: requirementListing = RequirementListingHelpers.GetRequirementListing(db, offer.ListingId); listingAppUser = AppUserHelpers.GetAppUser(db, requirementListing.ListingOriginatorAppUserId); break; } OfferManageView offerManageView = new OfferManageView() { OfferDetails = offer, AvailableListingDetails = availableListing, RequirementListingDetails = requirementListing, OfferAppUserDetails = offerAppUser, ListingAppUserDetails = listingAppUser, OfferBranchDetails = BranchHelpers.GetBranch(db, offerAppUser.CurrentBranchId), ListingBranchDetails = BranchHelpers.GetBranch(db, listingAppUser.CurrentBranchId), OfferAppUserSettings = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, offerAppUser.AppUserId), ListingAppUserSettings = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, listingAppUser.AppUserId) }; 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 offerManageView.InhouseOffer = OfferProcessHelpers.SetInhouseFlag(offer, thisAppUser, thisCompany); //set buttons bool?displayAcceptButton = null; bool?displayRejectButton = null; bool?displayCounterButton = null; bool?displayOfferButton = null; OfferProcessHelpers.SetOrderButtons(db, user, offerManageView, out displayAcceptButton, out displayRejectButton, out displayCounterButton, out displayOfferButton); offerManageView.DisplayAcceptButton = displayAcceptButton; offerManageView.DisplayRejectButton = displayRejectButton; offerManageView.DisplayCounterButton = displayCounterButton; offerManageView.DisplayOfferButton = displayOfferButton; return(offerManageView); }
public static List <Block> GetBlocksCreatedByUserCompany(ApplicationDbContext db, Guid appUserId) { Company userCompany = CompanyHelpers.GetCompanyForUser(db, appUserId); List <Block> list = (from b in db.Blocks where b.BlockedById == userCompany.CompanyId select b).ToList(); return(list); }
public static List <Friend> GetFriendsCreatedByUserCompany(ApplicationDbContext db, Guid appUserId) { Company userCompany = CompanyHelpers.GetCompanyForUser(db, appUserId); List <Friend> list = (from f in db.Friends where f.RequestedById == userCompany.CompanyId select f).ToList(); return(list); }
public static GroupAddView GetGroupAddView(ApplicationDbContext db, LevelEnum?level, Guid?ofReferenceId, Guid?byReferenceId, Guid?byAppUserId, Guid appUserId) { //Build a list of companies/branches/users from level if set List <GroupAddMemberView> members = new List <GroupAddMemberView>(); GroupAddView view = new GroupAddView(); if (level != null) //Build a list of users for this view { switch (level.Value) { case LevelEnum.Company: List <Company> companies = CompanyHelpers.GetAllCompaniesForGroupForUser(db, appUserId); foreach (Company company in companies) { members.Add(GroupMemberViewHelpers.CreateGroupAddMemberViewMember(db, false, company.CompanyId, company.CompanyName)); } break; case LevelEnum.Branch: List <Branch> branches = BranchHelpers.GetAllBranchesForGroupForUser(db, appUserId); foreach (Branch branch in branches) { members.Add(GroupMemberViewHelpers.CreateGroupAddMemberViewMember(db, false, branch.BranchId, branch.BranchName + ", " + branch.AddressTownCity)); } break; case LevelEnum.User: List <AppUser> users = AppUserHelpers.GetAllAppUsersForGroupForUser(db, appUserId); foreach (AppUser user in users) { members.Add(GroupMemberViewHelpers.CreateGroupAddMemberViewMember(db, false, user.AppUserId, user.FirstName + " " + user.LastName)); } break; } view.Type = level.Value; view.scratchEntry = false; view.Members = members; } else //return blank view with blank users as this is new from scratch { view.scratchEntry = true; //this will be used in view to stop the changing fo the 'type' field. //build members as User as this is the default List <AppUser> users = AppUserHelpers.GetAllAppUsersForGroupForUser(db, appUserId); foreach (AppUser user in users) { members.Add(GroupMemberViewHelpers.CreateGroupAddMemberViewMember(db, false, user.AppUserId, user.FirstName + " " + user.LastName)); } view.Members = members; } return(view); }
public static List <Company> GetAllCompaniesForGroupForUser(ApplicationDbContext db, Guid appUserId) { List <Company> allCompanies = GetAllCompanies(db); //Remove company for current user Company userCompany = CompanyHelpers.GetCompanyForUser(db, appUserId); allCompanies.Remove(userCompany); return(allCompanies); }
public static List <UserActionView> GetActionsForViewsForUser(ApplicationDbContext db, IPrincipal user) { List <UserActionView> list = new List <UserActionView>(); List <UserAction> userActionList = UserActionHelpers.GetActionsForUser(db, user); foreach (UserAction userAction in userActionList) { string referenceName = ""; switch (userAction.ActionLevel) { case LevelEnum.Company: referenceName = CompanyHelpers.GetCompanyNameTownPostCode(db, userAction.ReferenceKey); break; case LevelEnum.Branch: referenceName = BranchHelpers.GetBranchNameTownPostCode(db, userAction.ReferenceKey); break; case LevelEnum.User: referenceName = AppUserHelpers.GetAppUserName(db, userAction.ReferenceKey); break; } string createdByName = ""; //Get the user that created the action. Note, this could be at Company or Branch level, so try the user first, if that //fails then work through a switch try { createdByName = AppUserHelpers.GetAppUserName(db, userAction.CreatedBy); } catch { switch (userAction.ActionLevel) { case LevelEnum.Company: createdByName = CompanyHelpers.GetCompanyNameTownPostCode(db, userAction.CreatedBy); break; case LevelEnum.Branch: createdByName = BranchHelpers.GetBranchNameTownPostCode(db, userAction.CreatedBy); break; } } list.Add(CreateUserActionView(userAction, referenceName, createdByName)); } return(list); }
public static List <GroupListView> GetGroupListViewsCreatedByUser(ApplicationDbContext db, Guid appUserId) { List <GroupListView> list = new List <GroupListView>(); List <Group> allGroupsCreatedByUser = GroupHelpers.GetGroupsCreatedByUser(db, appUserId); foreach (Group group in allGroupsCreatedByUser) { //Get members of the group List <GroupMember> groupMembers = GroupMemberHelpers.GetMembersForGroup(db, group.GroupId); List <GroupMemberListView> groupMembersView = new List <GroupMemberListView>(); foreach (GroupMember member in groupMembers) { string memberName = null; switch (member.Type) { case LevelEnum.User: memberName = AppUserHelpers.GetAppUserName(db, member.ReferenceId); break; case LevelEnum.Branch: memberName = BranchHelpers.GetBranchNameTownPostCode(db, member.ReferenceId); break; case LevelEnum.Company: memberName = CompanyHelpers.GetCompanyNameTownPostCode(db, member.ReferenceId); break; } GroupMemberListView groupMemberListView = new GroupMemberListView() { GroupMember = member, GroupMemberName = memberName }; groupMembersView.Add(groupMemberListView); } //create view record to add to list of view records GroupListView view = new GroupListView(); view.Group = group; view.GroupOriginatorName = AppUserHelpers.GetAppUserName(db, view.Group.GroupOriginatorAppUserId); view.Members = groupMembersView; list.Add(view); } return(list); }
public static CompanyAdminView GetCompanyAdminView(ApplicationDbContext db, IPrincipal user) { //get company Company company = CompanyHelpers.GetCompanyForUser(user); //Get linked branches to this company List <Branch> branches = BranchHelpers.GetBranchesForCompany(db, company.CompanyId); //Build view CompanyAdminView companyAdminView = new CompanyAdminView() { CompanyDetails = company, RelatedBranches = branches }; return(companyAdminView); }
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 GroupAddView GetGroupAddView(ApplicationDbContext db, string groupName, string level, IPrincipal user) { List <GroupAddMemberView> members = new List <GroupAddMemberView>(); GroupAddView view = new GroupAddView(); LevelEnum levelEnum = LevelEnum.User; switch (level) { case "Company": levelEnum = LevelEnum.Company; List <Company> companies = CompanyHelpers.GetAllCompaniesForGroupForUser(db, AppUserHelpers.GetAppUserIdFromUser(user)); foreach (Company company in companies) { members.Add(GroupMemberViewHelpers.CreateGroupAddMemberViewMember(db, false, company.CompanyId, company.CompanyName)); } break; case "Branch": levelEnum = LevelEnum.Branch; List <Branch> branches = BranchHelpers.GetAllBranchesForGroupForUser(db, AppUserHelpers.GetAppUserIdFromUser(user)); foreach (Branch branch in branches) { members.Add(GroupMemberViewHelpers.CreateGroupAddMemberViewMember(db, false, branch.BranchId, branch.BranchName + ", " + branch.AddressTownCity)); } break; case "User": levelEnum = LevelEnum.User; List <AppUser> users = AppUserHelpers.GetAllAppUsersForGroupForUser(db, AppUserHelpers.GetAppUserIdFromUser(user)); foreach (AppUser appUser in users) { members.Add(GroupMemberViewHelpers.CreateGroupAddMemberViewMember(db, false, appUser.AppUserId, appUser.FirstName + " " + appUser.LastName)); } break; } view.Name = groupName; view.Type = levelEnum; view.scratchEntry = true; //this only comes from the scratch entry values view.Members = members; return(view); }
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 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 bool UpdateCompanyFromCompanyAdminView(ApplicationDbContext db, CompanyAdminView companyAdminView) { try { Company company = CompanyHelpers.UpdateCompany(db, companyAdminView.CompanyDetails.CompanyId, companyAdminView.CompanyDetails.HeadOfficeBranchId, companyAdminView.CompanyDetails.CompanyName, companyAdminView.CompanyDetails.CompanyRegistrationDetails, companyAdminView.CompanyDetails.CharityRegistrationDetails, companyAdminView.CompanyDetails.VATRegistrationDetails, companyAdminView.CompanyDetails.AllowBranchTrading, companyAdminView.CompanyDetails.PrivacyLevel, companyAdminView.CompanyDetails.EntityStatus ); return(true); } catch (Exception e) { Console.WriteLine("{0} Exception caught.", e); return(false); } }
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 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 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 <BlockView> GetBlockViewByType(ApplicationDbContext db, Guid appUserId, LevelEnum type) { List <BlockView> list = new List <BlockView>(); List <Block> blockList = null; //Depending on type passed through will depend on what level of blocks we are collecting switch (type) { case LevelEnum.User: blockList = BlockHelpers.GetBlocksCreatedByUser(db, appUserId); break; case LevelEnum.Branch: blockList = BlockHelpers.GetBlocksCreatedByUserBranches(db, appUserId); break; case LevelEnum.Company: blockList = BlockHelpers.GetBlocksCreatedByUserCompany(db, appUserId); break; } foreach (Block block in blockList) { //get the user/branch/company names depending on the block type string nameBy = ""; string nameOn = ""; switch (block.Type) { case LevelEnum.User: nameBy = AppUserHelpers.GetAppUserName(db, block.BlockedById); nameOn = AppUserHelpers.GetAppUserName(db, block.BlockedOfId); break; case LevelEnum.Branch: nameBy = BranchHelpers.GetBranchNameTownPostCode(db, block.BlockedById); nameOn = BranchHelpers.GetBranchNameTownPostCode(db, block.BlockedOfId); break; case LevelEnum.Company: nameBy = CompanyHelpers.GetCompanyNameTownPostCode(db, block.BlockedById); nameOn = CompanyHelpers.GetCompanyNameTownPostCode(db, block.BlockedOfId); break; } string blockedByUserName = AppUserHelpers.GetAppUserName(db, block.BlockedByUserId); bool blockedByLoggedInUser = false; if (block.BlockedByUserId == appUserId) { blockedByLoggedInUser = true; } BlockView view = new BlockView() { BlockId = block.BlockId, Type = block.Type, BlockedByName = nameBy, BlockedByUserName = blockedByUserName, BlockedOfName = nameOn, BlockedOn = block.BlockedOn, BlockedByLoggedInUser = blockedByLoggedInUser }; list.Add(view); } return(list); }
public static List <GroupListView> GetGroupListViewsRelevantToUser(ApplicationDbContext db, Guid appUserId) { List <GroupListView> list = new List <GroupListView>(); List <Group> allGroupsRelevantUser = new List <Group>(); //Get user groups containing this user allGroupsRelevantUser = GroupHelpers.GetGroupsForUser(db, appUserId); //Get branch groups containing this users branches List <Branch> usersBranches = BranchHelpers.GetBranchesForUser(db, appUserId); foreach (Branch branch in usersBranches) { List <Group> groups = GroupHelpers.GetGroupsForTypeAndReferenceId(db, LevelEnum.Branch, branch.BranchId); foreach (Group group in groups) { allGroupsRelevantUser.Add(group); } } //Get company groups containing this users company List <Group> companyGroups = GroupHelpers.GetGroupsForTypeAndReferenceId(db, LevelEnum.Company, CompanyHelpers.GetCompanyForUser(db, appUserId).CompanyId); foreach (Group group in companyGroups) { allGroupsRelevantUser.Add(group); } foreach (Group group in allGroupsRelevantUser) { //Get members of the group List <GroupMember> groupMembers = GroupMemberHelpers.GetMembersForGroup(db, group.GroupId); List <GroupMemberListView> groupMembersView = new List <GroupMemberListView>(); foreach (GroupMember member in groupMembers) { string memberName = null; switch (member.Type) { case LevelEnum.User: memberName = AppUserHelpers.GetAppUserName(db, member.ReferenceId); break; case LevelEnum.Branch: memberName = BranchHelpers.GetBranchNameTownPostCode(db, member.ReferenceId); break; case LevelEnum.Company: memberName = CompanyHelpers.GetCompanyNameTownPostCode(db, member.ReferenceId); break; } GroupMemberListView groupMemberListView = new GroupMemberListView() { GroupMember = member, GroupMemberName = memberName }; groupMembersView.Add(groupMemberListView); } //create view record to add to list of view records GroupListView view = new GroupListView(); view.Group = group; view.GroupOriginatorName = AppUserHelpers.GetAppUserName(db, view.Group.GroupOriginatorAppUserId); view.Members = groupMembersView; list.Add(view); } return(list); }
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); }
public static SelectList AllCompaniesListDropDown(Guid companyId) { return(new SelectList(CompanyHelpers.GetAllCompanies(), "CompanyId", "CompanyName", companyId)); }
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 List <FriendView> GetFriendViewByType(ApplicationDbContext db, Guid appUserId, LevelEnum type) { List <FriendView> list = new List <FriendView>(); List <Friend> friendList = null; //Depending on type passed through will depend on what level of friends we are collecting switch (type) { case LevelEnum.User: friendList = FriendHelpers.GetFriendsCreatedByUser(db, appUserId); break; case LevelEnum.Branch: friendList = FriendHelpers.GetFriendsCreatedByUserBranches(db, appUserId); break; case LevelEnum.Company: friendList = FriendHelpers.GetFriendsCreatedByUserCompany(db, appUserId); break; } foreach (Friend friend in friendList) { //get the user/branch/company names depending on the block type string nameBy = ""; string nameOn = ""; switch (friend.Type) { case LevelEnum.User: nameBy = AppUserHelpers.GetAppUserName(db, friend.RequestedById); nameOn = AppUserHelpers.GetAppUserName(db, friend.RequestedOfId); break; case LevelEnum.Branch: nameBy = BranchHelpers.GetBranchNameTownPostCode(db, friend.RequestedById); nameOn = BranchHelpers.GetBranchNameTownPostCode(db, friend.RequestedOfId); break; case LevelEnum.Company: nameBy = CompanyHelpers.GetCompanyNameTownPostCode(db, friend.RequestedById); nameOn = CompanyHelpers.GetCompanyNameTownPostCode(db, friend.RequestedOfId); break; } string friendedByUserName = AppUserHelpers.GetAppUserName(db, friend.RequestedByUserId); bool friendedByLoggedInUser = false; if (friend.RequestedByUserId == appUserId) { friendedByLoggedInUser = true; } FriendView view = new FriendView() { FriendId = friend.FriendId, Type = friend.Type, RequestedByName = nameBy, RequestedByUserName = friendedByUserName, RequestedOfName = nameOn, Status = friend.Status, RequestedOn = friend.RequestedOn, AccceptedOn = friend.AccceptedOn, RejectedOn = friend.RequestedOn, ClosedOn = friend.ClosedOn, ClosedBy = friend.ClosedBy, FriendedByLoggedInUser = friendedByLoggedInUser }; list.Add(view); } return(list); }