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 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 <UserAdminDetailsView> GetUserAdminDetailsView(ApplicationDbContext db, Guid organisationId, EntityStatusEnum?status) { List <AppUser> users = new List <AppUser>(); if (status == null) { users = AppUserHelpers.GetNonActiveAppUsersForOrganisation(db, organisationId); } else { users = AppUserHelpers.GetAppUsersForOrganisationWithEntityStatus(db, organisationId, status.Value); } List <UserAdminDetailsView> list = new List <UserAdminDetailsView>(); foreach (AppUser user in users) { UserAdminDetailsView view = new UserAdminDetailsView() { AppUserId = user.AppUserId, FirstName = user.FirstName, LastName = user.LastName, LoginEmail = user.LoginEmail, PrivacyLevel = user.PrivacyLevel, UserRole = user.UserRole, EntityStatus = user.EntityStatus }; list.Add(view); } return(list); }
public static Organisation UpdateOrganisation(ApplicationDbContext db, OrganisationAdminView view, IPrincipal user) { Organisation organisation = GetOrganisation(db, view.OrganisationId); organisation.OrganisationName = view.OrganisationName; organisation.BusinessType = view.BusinessType; organisation.AddressLine1 = view.AddressLine1; organisation.AddressLine2 = view.AddressLine2; organisation.AddressLine3 = view.AddressLine3; organisation.AddressTownCity = view.AddressTownCity; organisation.AddressCounty = view.AddressCounty; organisation.AddressPostcode = view.AddressPostcode; organisation.TelephoneNumber = view.TelephoneNumber; organisation.Email = view.Email; organisation.Website = view.Website; organisation.ContactName = view.ContactName; organisation.CompanyRegistrationDetails = view.CompanyRegistrationDetails; organisation.CharityRegistrationDetails = view.CharityRegistrationDetails; organisation.VATRegistrationDetails = view.VATRegistrationDetails; organisation.ListingPrivacyLevel = view.ListingPrivacyLevel; organisation.PrivacyLevel = view.PrivacyLevel; organisation.GroupPrivacyLevel = view.GroupPrivacyLevel; organisation.RecordChange = RecordChangeEnum.RecordUpdated; organisation.RecordChangeOn = DateTime.Now; organisation.RecordChangeBy = AppUserHelpers.GetAppUserIdFromUser(user); db.Entry(organisation).State = EntityState.Modified; db.SaveChanges(); return(organisation); }
public static void ReassignAllTasksForUserChangingRoleFromAdmin(ApplicationDbContext db, Guid appUserId) { List <UserTaskAssignment> list = (from uta in db.UserTaskAssignments where uta.AppUserId == appUserId select uta).ToList(); List <Guid> taskGuidsFromList = (from l in list select l.UserTaskId).Distinct().ToList(); //Find current admins for the company List <AppUser> admins = AppUserHelpers.GetAdminAppUsersForCompany(db, BranchHelpers.GetBranch(db, AppUserHelpers.GetAppUser(db, appUserId).CurrentBranchId).CompanyId); //now match up admins to tasks and if any are missing add them foreach (Guid task in taskGuidsFromList) { foreach (AppUser admin in admins) { List <Guid> assignedToTask = (from l in list where l.UserTaskId == task select l.AppUserId).ToList(); Guid result = assignedToTask.Find(x => x == admin.AppUserId); if (result == Guid.Empty) { CopyTaskFromUserAToUserB(db, task, appUserId, admin.AppUserId); } } } }
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 AvailableListing UpdateAvailableListingQuantities(ApplicationDbContext db, Guid listingId, ListingQuantityChange changeOfValue, decimal changeQty, IPrincipal user) { AvailableListing listing = AvailableListingHelpers.GetAvailableListing(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); }
/// <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); }
//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); }
public static BranchUser UpdateBranchUserRole(ApplicationDbContext db, Guid branchUserId, UserRoleEnum userRole) { BranchUser branchUser = GetBranchUser(db, branchUserId); //if user role changing FROM or TO Super/Admin user then set appUser flags accordingly if (userRole == UserRoleEnum.SuperUser) { AppUserHelpers.UpdateRoleFlags(db, branchUser.UserId, true, false); } if (userRole == UserRoleEnum.Admin) { AppUserHelpers.UpdateRoleFlags(db, branchUser.UserId, false, true); } //if role changes to Admin/Super user from anything else then add all company branches to user and activate if required if ((userRole == UserRoleEnum.SuperUser || userRole == UserRoleEnum.Admin) && (branchUser.UserRole != UserRoleEnum.SuperUser && branchUser.UserRole != UserRoleEnum.Admin)) { BranchUserHelpers.CreateBranchUserAdminRolesForUserForAllBranches(db, branchUser, userRole); } else { branchUser.UserRole = userRole; } branchUser.UserRole = userRole; db.Entry(branchUser).State = EntityState.Modified; db.SaveChanges(); return(branchUser); }
public static Group CreateGroup(ApplicationDbContext db, GroupViewCreateModel model, IPrincipal user) { Group group = new Group() { GroupId = Guid.NewGuid(), Name = model.Name, VisibilityLevel = model.VisibilityLevel, InviteLevel = model.InviteLevel, AcceptanceLevel = model.AcceptanceLevel, EntityStatus = EntityStatusEnum.Active, RecordChange = RecordChangeEnum.NewRecord, RecordChangeOn = DateTime.Now, RecordChangeBy = AppUserHelpers.GetAppUserIdFromUser(user), GroupOriginatorAppUserId = AppUserHelpers.GetAppUserIdFromUser(user), GroupOriginatorOrganisationId = AppUserHelpers.GetOrganisationIdFromUser(user), GroupOriginatorDateTime = DateTime.Now }; db.Groups.Add(group); db.SaveChanges(); //Add user Organisation as the initial group member GroupMembersHelpers.CreateGroupMember(db, group.GroupId, group.GroupOriginatorOrganisationId, user); return(group); }
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); }
public static AppUserSettings GetAppUserSettingsForUser(IPrincipal user) { ApplicationDbContext db = new ApplicationDbContext(); AppUserSettings appUserSettings = GetAppUserSettingsForUser(db, AppUserHelpers.GetAppUserIdFromUser(user)); db.Dispose(); return(appUserSettings); }
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 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 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 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 Organisation CreateOrganisation(HomeOrganisationDetailsView model, IPrincipal user) { Guid appUserId = AppUserHelpers.GetAppUserIdFromUser(user); ApplicationDbContext db = new ApplicationDbContext(); Organisation org = CreateOrganisation(db, model, appUserId); db.Dispose(); return(org); }
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 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 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 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 Offer RejectOffer(ApplicationDbContext db, IPrincipal user, Offer offer) { offer.OfferStatus = OfferStatusEnum.Rejected; offer.RejectedBy = AppUserHelpers.GetAppUserIdFromUser(user); offer.RejectedOn = DateTime.Now; db.Entry(offer).State = EntityState.Modified; db.SaveChanges(); return(offer); }
public static void RejoinGroup(ApplicationDbContext db, Guid groupId, Guid groupMemberId, IPrincipal user) { GroupMember member = GetGroupMemberFromGroup(db, groupId, groupMemberId); member.EntityStatus = EntityStatusEnum.Active; member.RecordChange = RecordChangeEnum.StatusChange; member.RecordChangeBy = AppUserHelpers.GetAppUserIdFromUser(user); member.RecordChangeOn = DateTime.Now; db.Entry(member).State = EntityState.Modified; db.SaveChanges(); }
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); }