public static RequiredListing CreateListing(ApplicationDbContext db, RequiredListingManageCreateViewModel model, IPrincipal user) { AppUser thisUser = AppUserHelpers.GetAppUser(db, user); Organisation thisOrg = OrganisationHelpers.GetOrganisation(db, thisUser.OrganisationId); RequiredListing listing = new RequiredListing() { ListingId = Guid.NewGuid(), ItemDescription = model.ItemDescription, ItemCategory = model.ItemCategory, ItemType = model.ItemType, QuantityRequired = model.QuantityRequired.Value, QuantityOutstanding = model.QuantityRequired.Value, UoM = model.UoM, RequiredFrom = model.RequiredFrom, RequiredTo = model.RequiredTo, AcceptDamagedItems = model.AcceptDamagedItems, AcceptOutOfDateItems = model.AcceptOutOfDateItems, CollectionAvailable = model.CollectionAvailable, ListingStatus = ItemEnums.ItemRequiredListingStatusEnum.Open, ListingOrganisationPostcode = thisOrg.AddressPostcode, RecordChange = GeneralEnums.RecordChangeEnum.NewRecord, RecordChangeBy = thisUser.AppUserId, RecordChangeOn = DateTime.Now, ListingOriginatorAppUserId = thisUser.AppUserId, ListingOriginatorOrganisationId = thisOrg.OrganisationId, ListingOriginatorDateTime = DateTime.Now }; db.RequiredListings.Add(listing); db.SaveChanges(); return(listing); }
public static List <AvailableListing> GetAllManageListingFilteredAvailableListings(ApplicationDbContext db, Guid appUserId, bool getHistory) { AppUser appUser = AppUserHelpers.GetAppUser(db, appUserId); Branch branch = BranchHelpers.GetBranch(db, appUser.CurrentBranchId); AppUserSettings settings = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, appUserId); var dateCheck = DateTime.MinValue; //Create list within the time frame if setting set List <AvailableListing> list = new List <AvailableListing>(); //Now bring in the Selection Level sort switch (settings.AvailableListingManageViewInternalSelectionLevel) { case InternalSearchLevelEnum.User: list = GetAllAvailableListingsForUser(db, appUserId, getHistory); break; case InternalSearchLevelEnum.Branch: //user's current branch to filter list = GetAllAvailableListingsForBranch(db, branch.BranchId, getHistory); break; case InternalSearchLevelEnum.Company: //user's current company to filter list = GetAllAvailableListingsForCompany(db, branch.CompanyId, getHistory); break; case InternalSearchLevelEnum.Group: //user's built group sets to filter ***TO BE DONE*** break; } return(list); }
public static Offer AcceptOffer(ApplicationDbContext db, Guid offerId, IPrincipal user) { Offer offer = db.Offers.Find(offerId); AppUser appUser = AppUserHelpers.GetAppUser(db, user); Order order = OrderHelpers.CreateOrder(db, offer, user); offer.OfferStatus = OfferStatusEnum.Accepted; offer.AcceptedBy = appUser.AppUserId; offer.AcceptedOn = DateTime.Now; offer.OrderId = order.OrderId; offer.OrderOriginatorAppUserId = appUser.AppUserId; offer.OrderOriginatorOrganisationId = appUser.OrganisationId; offer.OrderOriginatorDateTime = DateTime.Now; db.Entry(offer).State = EntityState.Modified; db.SaveChanges(); //set any related actions to Closed NotificationHelpers.RemoveNotificationsForOffer(db, offerId, user); //set any related current offers to closed if there is no stock left (currentOfferQuantity = 0) if (offer.CurrentOfferQuantity == 0) { OfferHelpers.CloseOffersRelatedToListing(db, offer.ListingId, user); } //Create Action to show order ready Organisation org = OrganisationHelpers.GetOrganisation(db, offer.OfferOriginatorOrganisationId); NotificationHelpers.CreateNotification(db, NotificationTypeEnum.NewOrderReceived, "New order received from " + org.OrganisationName, order.OrderId, appUser.AppUserId, org.OrganisationId, user); return(offer); }
public static List <GroupMemberViewModel> BuildGroupMemberViewListFromGroupMemberList(ApplicationDbContext db, List <GroupMember> groupMemberList) { List <GroupMemberViewModel> list = new List <GroupMemberViewModel>(); foreach (GroupMember member in groupMemberList) { Organisation organisaion = OrganisationHelpers.GetOrganisation(db, member.OrganisationId); AppUser addedBy = AppUserHelpers.GetAppUser(db, member.AddedBy); AppUser recordChangedBy = AppUserHelpers.GetAppUser(db, member.RecordChangeBy); GroupMemberViewModel item = new GroupMemberViewModel() { GroupMemberId = member.GroupMemberId, GroupId = member.GroupId, OrganisationDetails = organisaion, AddedBy = addedBy, AddedDateTime = member.AddedDateTime, Status = member.Status, RecordChange = member.RecordChange, RecordChangeOn = member.RecordChangeOn, RecordChangeBy = recordChangedBy }; list.Add(item); } return(list); }
public static List <Offer> GetAllManageListingFilteredOffers(ApplicationDbContext db, Guid appUserId, bool getHistory) { AppUser appUser = AppUserHelpers.GetAppUser(db, appUserId); Branch branch = BranchHelpers.GetBranch(db, appUser.CurrentBranchId); AppUserSettings settings = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, appUserId); //Create list List <Offer> list = new List <Offer>(); //Now bring in the Selection Level sort switch (settings.OffersManageViewInternalSelectionLevel) { case InternalSearchLevelEnum.User: list = GetAllOffersForUser(db, appUserId, getHistory); break; case InternalSearchLevelEnum.Branch: //user's current branch to filter list = GetAllOffersForBranch(db, branch.BranchId, getHistory); break; case InternalSearchLevelEnum.Company: //user's current company to filter list = GetAllOffersForCompany(db, branch.CompanyId, getHistory); break; case InternalSearchLevelEnum.Group: //user's built group sets to filter ***TO BE DONE*** break; } return(list); }
//Build a UserTasksViewModel record from a UserTask public static UserTasksViewModel CreateUserTasksViewModel(ApplicationDbContext db, UserTask task) { //set up the links to the relative areas AppUser appUser = null; //create the objects for the links to relative areas switch (task.TaskType) { case TaskTypeEnum.UserOnHold: appUser = AppUserHelpers.GetAppUser(db, task.ReferenceKey); break; } //build view UserTasksViewModel view = new UserTasksViewModel() { UserTaskId = task.UserTaskId, TaskType = task.TaskType, TaskDescription = task.TaskDescription, AppUser = appUser, ChangedOn = task.RecordChangeOn }; return(view); }
/// <summary> /// Gets the relevant Guid for the level of internal authorisation sent /// i.e. If this is a 'User' level of authorisation, then the current user AppUserId is returned. /// </summary> /// <param name="authorisationLevel"></param> /// <param name="user"></param> /// <returns></returns> public static Guid GetAuthorisationId(InternalSearchLevelEnum authorisationLevel, IPrincipal user) { Guid id = Guid.Empty; AppUser appUser = AppUserHelpers.GetAppUser(user); Branch branch = BranchHelpers.GetBranch(appUser.CurrentBranchId); AppUserSettings settings = AppUserSettingsHelpers.GetAppUserSettingsForUser(appUser.AppUserId); switch (settings.OrdersDespatchedAuthorisationManageViewLevel) { case InternalSearchLevelEnum.User: id = appUser.AppUserId; break; case InternalSearchLevelEnum.Branch: id = branch.BranchId; break; case InternalSearchLevelEnum.Company: id = branch.CompanyId; break; case InternalSearchLevelEnum.Group: //TO BE DONE LSLSLS id = appUser.AppUserId; break; } return(id); }
public static Company GetCompanyForUser(ApplicationDbContext db, Guid appUserId) { AppUser appUser = AppUserHelpers.GetAppUser(db, appUserId); BranchUser branchUser = BranchUserHelpers.GetBranchUser(db, appUser.AppUserId, appUser.CurrentBranchId); Company company = GetCompany(db, branchUser.CompanyId); return(company); }
public static List <AvailableListing> GetAllGeneralInfoFilteredAvailableListings(ApplicationDbContext db, Guid appUserId) { AppUser appUser = AppUserHelpers.GetAppUser(db, appUserId); Branch branch = BranchHelpers.GetBranch(db, appUser.CurrentBranchId); AppUserSettings settings = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, appUserId); var dateCheck = DateTime.MinValue; int settingsMaxDistance = settings.AvailableListingGeneralInfoMaxDistance ?? 0; //Create list within the time frame if setting set List <AvailableListing> list = (from rl in db.AvailableListings where ((rl.ListingStatus == ItemRequiredListingStatusEnum.Open || rl.ListingStatus == ItemRequiredListingStatusEnum.Partial) && rl.ListingOriginatorDateTime >= dateCheck) orderby rl.AvailableTo ?? DateTime.MaxValue select rl).ToList(); //Now bring in the Selection Level sort switch (settings.AvailableListingGeneralInfoExternalSelectionLevel) { case ExternalSearchLevelEnum.All: //do nothing break; case ExternalSearchLevelEnum.Branch: //user's current branch to filter list = list.Where(l => l.ListingOriginatorBranchId == branch.BranchId).ToList(); break; case ExternalSearchLevelEnum.Company: //user's current company to filter list = list.Where(l => l.ListingOriginatorCompanyId == branch.CompanyId).ToList(); break; case ExternalSearchLevelEnum.Group: //LSLSLS user's built group sets to filter ***TO BE DONE*** break; } //Now sort by distance if (settingsMaxDistance > 0) { List <AvailableListing> removeList = new List <AvailableListing>(); foreach (AvailableListing listing in list) { DistanceHelpers distance = new DistanceHelpers(); int distanceValue = distance.GetDistance(branch.AddressPostcode, listing.ListingBranchPostcode); if (distanceValue > settingsMaxDistance) { removeList.Add(listing); } } if (removeList.Count > 0) { list.RemoveAll(l => removeList.Contains(l)); } } return(list); }
public static Branch GetCurrentBranchForUser(ApplicationDbContext db, Guid appUserId) { AppUser appUser = AppUserHelpers.GetAppUser(db, appUserId); Branch branch = (from b in db.Branches where b.BranchId == appUser.CurrentBranchId select b).FirstOrDefault(); return(branch); }
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); }
public static List <Campaign> GetAllGeneralInfoFilteredCampaigns(ApplicationDbContext db, Guid appUserId) { AppUser appUser = AppUserHelpers.GetAppUser(db, appUserId); Branch branch = BranchHelpers.GetBranch(db, appUser.CurrentBranchId); AppUserSettings settings = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, appUserId); var dateCheck = DateTime.MinValue; int settingsMaxDistance = settings.CampaignGeneralInfoMaxDistance ?? 0; //Create list within the time frame if setting set List <Campaign> list = (from c in db.Campaigns where (c.EntityStatus == EntityStatusEnum.Active && c.CampaignOriginatorDateTime >= dateCheck) orderby c.CampaignEndDateTime ?? DateTime.MaxValue select c).ToList(); //Now bring in the Selection Level sort switch (settings.CampaignGeneralInfoExternalSelectionLevel) { case ExternalSearchLevelEnum.All: //do nothing break; case ExternalSearchLevelEnum.Branch: //user's current branch to filter list = list.Where(l => l.CampaignOriginatorBranchId == branch.BranchId).ToList(); break; case ExternalSearchLevelEnum.Company: //user's current company to filter list = list.Where(l => l.CampaignOriginatorCompanyId == branch.CompanyId).ToList(); break; case ExternalSearchLevelEnum.Group: //user's built group sets to filter ***TO BE DONE*** break; } //Now sort by distance if (settingsMaxDistance > 0) { List <Campaign> removeList = new List <Campaign>(); foreach (Campaign campaign in list) { DistanceHelpers distance = new DistanceHelpers(); int distanceValue = distance.GetDistance(branch.AddressPostcode, campaign.LocationAddressPostcode); if (distanceValue > settingsMaxDistance) { removeList.Add(campaign); } } if (removeList.Count > 0) { list.RemoveAll(l => removeList.Contains(l)); } } return(list); }
public static List <AppUser> GetAllAppUsersForGroupForUser(ApplicationDbContext db, Guid appUserId) { List <AppUser> list = GetAllAppUsers(db); //remove current user from list list.Remove(AppUserHelpers.GetAppUser(db, appUserId)); return(list); }
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 void DeleteAppUser(ApplicationDbContext db, Guid appUserId) { AppUser appUser = AppUserHelpers.GetAppUser(db, appUserId); db.AppUsers.Remove(appUser); AppUserSettingsHelpers.DeleteAppUserSettingsForUser(db, appUserId); db.SaveChanges(); }
public static AppUser UpdateEntityStatus(ApplicationDbContext db, Guid appUserId, EntityStatusEnum entityStatus) { AppUser appUser = AppUserHelpers.GetAppUser(db, appUserId); appUser.EntityStatus = entityStatus; db.Entry(appUser).State = EntityState.Modified; db.SaveChanges(); return(appUser); }
public static List <CampaignGeneralInfoView> GetAllCampaignsGeneralInfoView(ApplicationDbContext db, IPrincipal user) { List <CampaignGeneralInfoView> allCampaignsGeneralInfoView = new List <CampaignGeneralInfoView>(); AppUser appUser = AppUserHelpers.GetAppUser(db, user); AppUserSettings settings = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, appUser.AppUserId); Branch currentBranch = BranchHelpers.GetBranch(appUser.CurrentBranchId); List <Campaign> allCampaigns = CampaignHelpers.GetAllGeneralInfoFilteredCampaigns(db, appUser.AppUserId); foreach (Campaign campaign in allCampaigns) { bool userBlocked = false; bool branchBlocked = false; bool companyBlocked = false; BlockHelpers.GetBlocksForAllTypesForSpecificOfBy(db, campaign.CampaignOriginatorAppUserId, appUser.AppUserId, campaign.CampaignOriginatorBranchId, currentBranch.BranchId, campaign.CampaignOriginatorCompanyId, currentBranch.CompanyId, out userBlocked, out branchBlocked, out companyBlocked); bool userMatchedOwner = false; bool branchMatchedOwner = false; bool companyMatchedOwner = false; if (currentBranch.CompanyId == campaign.CampaignOriginatorCompanyId) { companyMatchedOwner = true; } if (currentBranch.BranchId == campaign.CampaignOriginatorBranchId) { branchMatchedOwner = true; } if (appUser.AppUserId == campaign.CampaignOriginatorAppUserId) { userMatchedOwner = true; } CampaignGeneralInfoView campaignGeneralInfoView = new CampaignGeneralInfoView() { Campaign = campaign, UserLevelBlock = userBlocked, BranchLevelBlock = branchBlocked, CompanyLevelBlock = companyBlocked, DisplayBlocks = settings.CampaignGeneralInfoDisplayBlockedListings, CompanyLevelOwner = companyMatchedOwner, DisplayMyCompanyRecords = settings.CampaignGeneralInfoDisplayMyUserListings, BranchLevelOwner = branchMatchedOwner, DisplayMyBranchRecords = settings.CampaignGeneralInfoDisplayMyBranchListings, UserLevelOwner = userMatchedOwner, DisplayMyRecords = settings.CampaignGeneralInfoDisplayMyUserListings }; allCampaignsGeneralInfoView.Add(campaignGeneralInfoView); } return(allCampaignsGeneralInfoView); }
public static Order CreateOrder(ApplicationDbContext db, Offer offer, IPrincipal user) { AppUser appUser = AppUserHelpers.GetAppUser(db, user); decimal orderQty = 0.00M; switch (offer.OfferStatus) { case OfferStatusEnum.New: case OfferStatusEnum.Reoffer: orderQty = offer.CurrentOfferQuantity; break; case OfferStatusEnum.Countered: orderQty = offer.CounterOfferQuantity.Value; break; } //Update Listing values switch (offer.ListingType) { case ListingTypeEnum.Available: AvailableListingHelpers.UpdateAvailableListingQuantities(db, offer.ListingId, ListingQuantityChange.Subtract, orderQty, user); break; case ListingTypeEnum.Requirement: RequiredListingHelpers.UpdateRequiredListingQuantities(db, offer.ListingId, ListingQuantityChange.Subtract, orderQty, user); break; } Order order = new Order() { OrderId = Guid.NewGuid(), ItemDescription = offer.ItemDescription, ListingType = offer.ListingType, OrderQuanity = orderQty, OrderInStatus = OrderInStatusEnum.New, OrderOutStatus = OrderOutStatusEnum.New, OrderCreationDateTime = DateTime.Now, OrderOriginatorAppUserId = appUser.AppUserId, OrderOriginatorOrganisationId = appUser.OrganisationId, OrderOriginatorDateTime = DateTime.Now, OfferId = offer.OfferId, OfferOriginatorAppUserId = offer.LastOfferOriginatorAppUserId ?? offer.OfferOriginatorAppUserId, OfferOriginatorOrganisationId = offer.OfferOriginatorOrganisationId, ListingId = offer.ListingId, ListingOriginatorAppUserId = offer.ListingOriginatorAppUserId, ListingOriginatorOrganisationId = offer.ListingOriginatorOrganisationId }; db.Orders.Add(order); db.SaveChanges(); return(order); }
public static Offer UpdateOffer(ApplicationDbContext db, Guid offerid, OfferStatusEnum offerStatus, decimal?currentOfferQuantity, decimal?counterOfferQuantity, IPrincipal user) { Offer offer = OfferHelpers.GetOffer(db, offerid); switch (offerStatus) { case OfferStatusEnum.Reoffer: //update offer value and move counter value to previous if (currentOfferQuantity.HasValue) { offer.CurrentOfferQuantity = currentOfferQuantity.Value; offer.PreviousCounterOfferQuantity = offer.CounterOfferQuantity; offer.CounterOfferQuantity = null; offer.LastOfferOriginatorAppUserId = AppUserHelpers.GetAppUserIdFromUser(user); offer.LastOfferOriginatorDateTime = DateTime.Now; offer.OfferStatus = offerStatus; db.Entry(offer).State = EntityState.Modified; db.SaveChanges(); } break; case OfferStatusEnum.Countered: //update counter value and move current offer to previous offer if (counterOfferQuantity.HasValue) { offer.CounterOfferQuantity = counterOfferQuantity; offer.PreviousOfferQuantity = offer.CurrentOfferQuantity; offer.CurrentOfferQuantity = 0.00M; if (!offer.CounterOfferOriginatorOrganisationId.HasValue) { AppUser appUser = AppUserHelpers.GetAppUser(db, AppUserHelpers.GetAppUserIdFromUser(user)); offer.CounterOfferOriginatorAppUserId = appUser.AppUserId; offer.CounterOfferOriginatorDateTime = DateTime.Now; offer.CounterOfferOriginatorOrganisationId = appUser.OrganisationId; } else { offer.LastCounterOfferOriginatorAppUserId = AppUserHelpers.GetAppUserIdFromUser(user); offer.LastCounterOfferOriginatorDateTime = DateTime.Now; } offer.OfferStatus = offerStatus; db.Entry(offer).State = EntityState.Modified; db.SaveChanges(); } break; } //Create Action Organisation org = OrganisationHelpers.GetOrganisation(db, AppUserHelpers.GetAppUser(db, AppUserHelpers.GetAppUserIdFromUser(user)).OrganisationId); NotificationHelpers.CreateNotification(db, NotificationTypeEnum.NewOfferReceived, "New offer received from " + org.OrganisationName, offer.OfferId, offer.ListingOriginatorAppUserId.Value, offer.ListingOriginatorOrganisationId.Value, user); return(offer); }
public static DashboardView GetDashboardViewLogin(ApplicationDbContext db, IPrincipal user) { AppUser appUser = AppUserHelpers.GetAppUser(db, user); //initialise the view DashboardView dashboardView = new DashboardView(); //get the campaigns and listings for this user List <Campaign> campaignsForUser = CampaignHelpers.GetAllCampaignsForUser(db, appUser.AppUserId, false); dashboardView.CampaignList = campaignsForUser; List <Campaign> campaignsDashboardList = CampaignHelpers.GetAllDashboardFilteredCampaigns(db, appUser.AppUserId); dashboardView.CampaignDashboardList = campaignsDashboardList; List <RequirementListing> requirementListingsForUser = RequirementListingHelpers.GetAllRequirementListingsForUser(db, appUser.AppUserId, false); dashboardView.RequirementListingList = requirementListingsForUser; List <RequirementListing> requirementListingDashboardList = RequirementListingHelpers.GetAllDashboardFilteredRequirementListings(db, appUser.AppUserId); dashboardView.RequirementListingDashboardList = requirementListingDashboardList; List <AvailableListing> availableListingsForUser = AvailableListingHelpers.GetAllAvailableListingsForUser(db, appUser.AppUserId, false); dashboardView.AvailableListingList = availableListingsForUser; List <AvailableListing> availableListingDashboardList = AvailableListingHelpers.GetAllDashboardFilteredAvailableListings(db, appUser.AppUserId); dashboardView.AvailableListingDashboardList = availableListingDashboardList; List <Offer> offersForUser = OfferHelpers.GetAllOffersForUser(db, appUser.AppUserId, false); dashboardView.OfferList = offersForUser; List <Order> ordersForUser = OrderHelpers.GetAllOrdersForUser(db, appUser.AppUserId, false); dashboardView.OrderList = ordersForUser; //get listings for admin areas if this user is not a 'User' - i.e. is Manager, Admin etc. if (user.Identity.GetCurrentUserRole() != "User") { List <UserTask> tasksForUser = UserTaskHelpers.GetUserTasksForUser(db, appUser.AppUserId); //LSLSLS get list of 'actions' once written dashboardView.UserTaskList = tasksForUser; } return(dashboardView); }
public static List <OfferManageView> GetAllOffersManageView(ApplicationDbContext db, IPrincipal user, bool getHistory) { List <OfferManageView> allOffersManageView = new List <OfferManageView>(); AppUser appUser = AppUserHelpers.GetAppUser(db, user); List <Offer> allOffersForUser = OfferHelpers.GetAllManageListingFilteredOffers(db, appUser.AppUserId, getHistory); foreach (Offer offerForUser in allOffersForUser) { allOffersManageView.Add(GetOfferManageViewForOffer(db, offerForUser, user)); } return(allOffersManageView); }
//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 List <Offer> CreateOffers(ApplicationDbContext db, AvailableListingGeneralViewListModel availableModel, RequiredListingGeneralViewListModel requiredModel, ListingTypeEnum listingType, IPrincipal user) { AppUser currentUser = AppUserHelpers.GetAppUser(db, user); List <Offer> createdOffers = new List <Offer>(); if (listingType == ListingTypeEnum.Available) { //go through the records, if there are offer qty's > 0 then create an offer from these foreach (AvailableListingGeneralViewModel item in availableModel.Listing) { if (item.OfferQty.HasValue) { if (item.OfferQty > 0) { //only create offers if they don't already exist if (OfferHelpers.GetOfferForListingByUser(db, item.ListingId, currentUser.AppUserId, currentUser.OrganisationId, LevelEnum.Organisation) == null) { createdOffers.Add(CreateOffer(db, item.ListingId, item.OfferQty, listingType, currentUser, user)); } } } } } if (listingType == ListingTypeEnum.Requirement) { //go through the records, if there are offer qty's > 0 then create an offer from these foreach (RequiredListingGeneralViewModel item in requiredModel.Listing) { if (item.RequiredQty.HasValue) { if (item.RequiredQty > 0) { //only create offers if they don't already exist if (OfferHelpers.GetOfferForListingByUser(db, item.ListingId, currentUser.AppUserId, currentUser.OrganisationId, LevelEnum.Organisation) == null) { createdOffers.Add(CreateOffer(db, item.ListingId, item.RequiredQty, listingType, currentUser, user)); } } } } } return(createdOffers); }
public static Offer RejectOffer(ApplicationDbContext db, Guid offerId, IPrincipal user) { Offer offer = db.Offers.Find(offerId); AppUser appUser = AppUserHelpers.GetAppUser(db, user); offer.OfferStatus = OfferStatusEnum.Rejected; offer.RejectedBy = appUser.AppUserId; offer.RejectedOn = DateTime.Now; db.Entry(offer).State = EntityState.Modified; db.SaveChanges(); //set any related actions to Closed NotificationHelpers.RemoveNotificationsForOffer(db, offerId, user); return(offer); }
public static List <UserTask> GetUserTasksForOrganisationFromUser(ApplicationDbContext db, IPrincipal user, bool getHistory) { AppUser appUser = AppUserHelpers.GetAppUser(db, user); EntityStatusEnum status = EntityStatusEnum.Active; if (getHistory) { status = EntityStatusEnum.Inactive; } List <UserTask> list = (from ut in db.UserTasks where (ut.OrganisationId == appUser.OrganisationId && ut.EntityStatus == status) orderby ut.RecordChangeBy ascending select ut).Distinct().ToList(); return(list); }
public static List <Notification> GetNotificationsForOrganisationFromUser(ApplicationDbContext db, IPrincipal user, bool getHistory) { AppUser appUser = AppUserHelpers.GetAppUser(db, user); EntityStatusEnum status = EntityStatusEnum.Active; if (getHistory) { status = EntityStatusEnum.Inactive; } List <Notification> list = (from n in db.Notifications where (n.OrganisationId == appUser.OrganisationId && n.EntityStatus == status) orderby n.RecordChangeBy ascending select n).Distinct().ToList(); return(list); }
public static List <GroupViewModel> GetGroupsViewCreatedByOrg(ApplicationDbContext db, IPrincipal user) { List <GroupViewModel> groupsViewCreatedByOrg = new List <GroupViewModel>(); //get organisation from User Organisation organisation = OrganisationHelpers.GetOrganisation(db, AppUserHelpers.GetOrganisationIdFromUser(db, user)); //get list of groups created by this organisation List <Group> groupsCreatedByOrg = GroupHelpers.GetGroupsCreatedByOrg(db, organisation.OrganisationId); //build view foreach (Group group in groupsCreatedByOrg) { //Build members view for this group List <GroupMemberViewModel> membersView = GroupMembersViewHelpers.GetGroupMembersViewForGroup(db, group.GroupId); //Build objects of guid details AppUser recordChangedBy = AppUserHelpers.GetAppUser(db, group.RecordChangeBy); AppUser groupOriginatorAppUser = AppUserHelpers.GetAppUser(db, group.GroupOriginatorAppUserId); Organisation groupOriginatorOrganisation = OrganisationHelpers.GetOrganisation(db, group.GroupOriginatorOrganisationId); //Build group view GroupViewModel groupView = new GroupViewModel() { GroupId = group.GroupId, Name = group.Name, InviteLevel = group.InviteLevel, VisibilityLevel = group.VisibilityLevel, AcceptanceLevel = group.AcceptanceLevel, EntityStatus = group.EntityStatus, RecordChange = group.RecordChange, RecordChangeOn = group.RecordChangeOn, RecordChangeBy = recordChangedBy, GroupOriginatorAppUser = groupOriginatorAppUser, GroupOriginatorOrganisation = groupOriginatorOrganisation, GroupOriginatorDateTime = group.GroupOriginatorDateTime, GroupMembers = membersView }; groupsViewCreatedByOrg.Add(groupView); } return(groupsViewCreatedByOrg); }
public static List <GroupViewModel> GetGroupsViewContainingOrg(ApplicationDbContext db, EntityStatusEnum memberStatus, IPrincipal user) { List <GroupViewModel> groupsViewContainingOrg = new List <GroupViewModel>(); //get organisation from User Organisation organisation = OrganisationHelpers.GetOrganisation(db, AppUserHelpers.GetOrganisationIdFromUser(db, user)); //get list of groups containing this organisation List <Group> groupsContainingOrg = GroupHelpers.GetGroupsContainingOrg(db, organisation.OrganisationId, memberStatus); //build view foreach (Group group in groupsContainingOrg) { //Build members view for this group (NOTE, this will not be added to for this list as this is just a list of groups we are part of, no need currently to show the members. List <GroupMemberViewModel> membersView = new List <GroupMemberViewModel>(); //If we do need to show the members then change this to "List<GroupMemberViewModel> membersView = GroupMembersViewHelpers.GetGroupMembersViewForGroup(db, group.GroupId);" //Build objects of guid details AppUser recordChangedBy = AppUserHelpers.GetAppUser(db, group.RecordChangeBy); AppUser groupOriginatorAppUser = AppUserHelpers.GetAppUser(db, group.GroupOriginatorAppUserId); Organisation groupOriginatorOrganisation = OrganisationHelpers.GetOrganisation(db, group.GroupOriginatorOrganisationId); //Build group view GroupViewModel groupView = new GroupViewModel() { GroupId = group.GroupId, Name = group.Name, InviteLevel = group.InviteLevel, VisibilityLevel = group.VisibilityLevel, AcceptanceLevel = group.AcceptanceLevel, EntityStatus = group.EntityStatus, RecordChange = group.RecordChange, RecordChangeOn = group.RecordChangeOn, RecordChangeBy = recordChangedBy, GroupOriginatorAppUser = groupOriginatorAppUser, GroupOriginatorOrganisation = groupOriginatorOrganisation, GroupOriginatorDateTime = group.GroupOriginatorDateTime, GroupMembers = membersView }; groupsViewContainingOrg.Add(groupView); } return(groupsViewContainingOrg); }
public static List <Branch> GetBranchesForUserForAdminView(ApplicationDbContext db, Guid appUserId) { AppUser currentAppUser = AppUserHelpers.GetAppUser(db, appUserId); Branch currentBranch = BranchHelpers.GetBranch(db, currentAppUser.CurrentBranchId); BranchUser currentBranchUser = BranchUserHelpers.GetBranchUser(db, appUserId, currentAppUser.CurrentBranchId, currentBranch.CompanyId); List <BranchUser> branchUserForUser = BranchUserHelpers.GetBranchUsersForUserWithRole(db, appUserId, currentBranchUser.UserRole); List <Branch> branchesForUser = new List <Branch>(); foreach (BranchUser branchUser in branchUserForUser) { branchesForUser.Add(BranchHelpers.GetBranch(db, branchUser.BranchId)); } List <Branch> branchesForUserDistinct = branchesForUser.Distinct().ToList(); return(branchesForUserDistinct); }
public static List <OrderManageView> GetAllOrdersManageViewForUser(ApplicationDbContext db, IPrincipal user) { List <OrderManageView> allOrdersManageView = new List <OrderManageView>(); AppUser appUser = AppUserHelpers.GetAppUser(db, user); List <Order> allOrdersForUser = OrderHelpers.GetAllOrdersForUser(db, appUser.AppUserId, false); foreach (Order orderForUser in allOrdersForUser) { OrderManageView orderManageView = new OrderManageView() { OrderDetails = orderForUser }; allOrdersManageView.Add(orderManageView); } return(allOrdersManageView); }