Beispiel #1
0
        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);
        }
Beispiel #2
0
        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 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);
        }
Beispiel #4
0
        public static AppUserSettings GetAppUserSettingsForUser(IPrincipal user)
        {
            ApplicationDbContext db = new ApplicationDbContext();
            AppUserSettings      appUserSettings = GetAppUserSettingsForUser(db, AppUserHelpers.GetAppUserIdFromUser(user));

            db.Dispose();
            return(appUserSettings);
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        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);
        }
Beispiel #9
0
        public static Notification UpdateEntityStatus(ApplicationDbContext db, Guid notificationId, EntityStatusEnum entityStatus, IPrincipal user)
        {
            Notification notification = GetNotification(db, notificationId);

            notification.EntityStatus   = entityStatus;
            notification.RecordChange   = RecordChangeEnum.StatusChange;
            notification.RecordChangeOn = DateTime.Now;
            notification.RecordChangeBy = AppUserHelpers.GetAppUserIdFromUser(user);

            db.Entry(notification).State = EntityState.Modified;
            db.SaveChanges();

            return(notification);
        }
        public static AvailableListing UpdateAvailableListingListingStatus(ApplicationDbContext db, Guid listingId, ItemRequiredListingStatusEnum listingStatus, IPrincipal user)
        {
            AvailableListing listing = GetAvailableListing(db, listingId);

            if (listing != null)
            {
                listing.ListingStatus  = listingStatus;
                listing.RecordChange   = GeneralEnums.RecordChangeEnum.ListingStatusChange;
                listing.RecordChangeBy = AppUserHelpers.GetAppUserIdFromUser(user);
                listing.RecordChangeOn = DateTime.Now;

                db.Entry(listing).State = EntityState.Modified;
                db.SaveChanges();
            }

            return(listing);
        }
Beispiel #11
0
        public static Group UpdateGroup(ApplicationDbContext db, GroupViewEditModel model, IPrincipal user)
        {
            Group group = GetGroup(db, model.GroupId);

            group.Name            = model.Name;
            group.VisibilityLevel = model.VisibilityLevel;
            group.InviteLevel     = model.InviteLevel;
            group.AcceptanceLevel = model.AcceptanceLevel;
            group.RecordChange    = RecordChangeEnum.NewRecord;
            group.RecordChangeOn  = DateTime.Now;
            group.RecordChangeBy  = AppUserHelpers.GetAppUserIdFromUser(user);

            db.Entry(group).State = EntityState.Modified;
            db.SaveChanges();

            return(group);
        }
Beispiel #12
0
        public static Notification UpdateNotificationEntityStatus(ApplicationDbContext db, Guid?notificationId, Notification action, EntityStatusEnum newStatus, IPrincipal user)
        {
            if (action == null)
            {
                action = NotificationHelpers.GetNotification(db, notificationId.Value);
            }

            action.EntityStatus   = newStatus;
            action.RecordChange   = RecordChangeEnum.StatusChange;
            action.RecordChangeBy = AppUserHelpers.GetAppUserIdFromUser(user);
            action.RecordChangeOn = DateTime.Now;

            db.Entry(action).State = EntityState.Modified;
            db.SaveChanges();

            return(action);
        }
Beispiel #13
0
        public static Offer UpdateStatus(ApplicationDbContext db, Guid offerId, OfferStatusEnum newStatus, IPrincipal user)
        {
            Offer offer = OfferHelpers.GetOffer(db, offerId);

            offer.OfferStatus = newStatus;

            if (newStatus == OfferStatusEnum.ClosedNoStock)
            {
                offer.ClosedNoStockBy = AppUserHelpers.GetAppUserIdFromUser(user);
                offer.ClosedNoStockOn = DateTime.Now;
            }

            db.Entry(offer).State = EntityState.Modified;
            db.SaveChanges();

            return(offer);
        }
        public static AvailableListing UpdateAvailableListing(ApplicationDbContext db, AvailableListingDetailsViewModel model, IPrincipal user)
        {
            AvailableListing listing = GetAvailableListing(db, model.ListingId);

            decimal qtyAvailable;

            decimal.TryParse(model.QuantityAvailable.ToString(), out qtyAvailable);
            decimal qtyFulfilled;

            decimal.TryParse(model.QuantityFulfilled.ToString(), out qtyFulfilled);
            decimal qtyOutstanding;

            decimal.TryParse(model.QuantityOutstanding.ToString(), out qtyOutstanding);

            if (listing != null)
            {
                listing.ItemDescription     = model.ItemDescription;
                listing.ItemCategory        = model.ItemCategory;
                listing.ItemType            = model.ItemType;
                listing.QuantityAvailable   = qtyAvailable;
                listing.QuantityFulfilled   = qtyFulfilled;
                listing.QuantityOutstanding = qtyOutstanding;
                listing.UoM                         = model.UoM;
                listing.AvailableFrom               = model.AvailableFrom;
                listing.AvailableTo                 = model.AvailableTo;
                listing.ItemCondition               = model.ItemCondition;
                listing.DisplayUntilDate            = model.DisplayUntilDate;
                listing.SellByDate                  = model.SellByDate;
                listing.UseByDate                   = model.UseByDate;
                listing.DeliveryAvailable           = model.DeliveryAvailable;
                listing.ListingStatus               = model.ListingStatus;
                listing.ListingOrganisationPostcode = model.ListingOrganisationPostcode;
                listing.RecordChange                = GeneralEnums.RecordChangeEnum.ListingStatusChange;
                listing.RecordChangeBy              = AppUserHelpers.GetAppUserIdFromUser(user);
                listing.RecordChangeOn              = DateTime.Now;

                db.Entry(listing).State = EntityState.Modified;
                db.SaveChanges();
            }

            return(listing);
        }
Beispiel #15
0
        public static Group UpdateEntityStatus(ApplicationDbContext db, Guid groupId, EntityStatusEnum entityStatus, IPrincipal user)
        {
            try
            {
                Group group = db.Groups.Find(groupId);

                group.EntityStatus   = entityStatus;
                group.RecordChange   = RecordChangeEnum.StatusChange;
                group.RecordChangeBy = AppUserHelpers.GetAppUserIdFromUser(user);
                group.RecordChangeOn = DateTime.Now;

                db.Entry(group).State = EntityState.Modified;
                db.SaveChanges();

                return(group);
            }
            catch
            {
                return(null);
            }
        }
Beispiel #16
0
        public static Notification CreateNotification(ApplicationDbContext db, NotificationTypeEnum notificationType, string notificationDescription, Guid referenceKey, Guid referenceAppUserId, Guid referenceOrganisationId, IPrincipal user)
        {
            Notification notification = new Notification()
            {
                NotificationId          = Guid.NewGuid(),
                NotificationType        = notificationType,
                NotificationDescription = notificationDescription,
                ReferenceKey            = referenceKey,
                AppUserId      = referenceAppUserId,
                OrganisationId = referenceOrganisationId,
                EntityStatus   = EntityStatusEnum.Active,
                RecordChange   = RecordChangeEnum.NewRecord,
                RecordChangeBy = AppUserHelpers.GetAppUserIdFromUser(user),
                RecordChangeOn = DateTime.Now
            };

            db.Notifications.Add(notification);
            db.SaveChanges();

            return(notification);
        }
Beispiel #17
0
        //Create a group member record from the GroupMemberViewCreateModel
        public static GroupMember CreateGroupMember(ApplicationDbContext db, Guid groupId, Guid organisationId, IPrincipal user)
        {
            GroupMember member = new GroupMember()
            {
                GroupMemberId  = Guid.NewGuid(),
                GroupId        = groupId,
                OrganisationId = organisationId,
                AddedBy        = AppUserHelpers.GetAppUserIdFromUser(user),
                AddedDateTime  = DateTime.Now,
                EntityStatus   = EntityStatusEnum.Active,
                Status         = GroupMemberStatusEnum.Accepted,
                RecordChange   = RecordChangeEnum.NewRecord,
                RecordChangeOn = DateTime.Now,
                RecordChangeBy = AppUserHelpers.GetAppUserIdFromUser(user)
            };

            db.GroupMembers.Add(member);
            db.SaveChanges();

            return(member);
        }
Beispiel #18
0
        public static Group CreateGroupFromGroupAddView(ApplicationDbContext db, GroupAddView view, IPrincipal user)
        {
            Group group = new Group()
            {
                GroupId                  = Guid.NewGuid(),
                Name                     = view.Name,
                Type                     = view.Type,
                VisibilityLevel          = view.VisibilityLevel,
                InviteLevel              = view.InviteLevel,
                AcceptanceLevel          = view.AcceptanceLevel,
                GroupOriginatorAppUserId = AppUserHelpers.GetAppUserIdFromUser(user),
                GroupOriginatorDateTime  = DateTime.Now
            };

            db.Groups.Add(group);
            db.SaveChanges();

            GroupViewHelpers.CreateGroupMembersFromGroupAddView(db, view, group);

            return(group);
        }
Beispiel #19
0
        public static UserTask CreateUserTask(ApplicationDbContext db, TaskTypeEnum taskType, string taskDescription, Guid referenceKey, string referenceEmail, Guid referenceOrganisationId, IPrincipal user)
        {
            UserTask userTask = new UserTask()
            {
                UserTaskId      = Guid.NewGuid(),
                TaskType        = taskType,
                TaskDescription = taskDescription,
                ReferenceKey    = referenceKey,
                ReferenceEmail  = referenceEmail,
                OrganisationId  = referenceOrganisationId,
                EntityStatus    = EntityStatusEnum.Active,
                RecordChange    = RecordChangeEnum.NewRecord,
                RecordChangeBy  = AppUserHelpers.GetAppUserIdFromUser(user),
                RecordChangeOn  = DateTime.Now
            };

            db.UserTasks.Add(userTask);
            db.SaveChanges();

            return(userTask);
        }
Beispiel #20
0
        public static RequiredListing UpdateRequiredListing(ApplicationDbContext db, RequiredListingDetailsViewModel model, IPrincipal user)
        {
            RequiredListing listing = GetRequiredListing(db, model.ListingId);

            decimal qtyRequired;

            decimal.TryParse(model.QuantityRequired.ToString(), out qtyRequired);
            decimal qtyFulfilled;

            decimal.TryParse(model.QuantityFulfilled.ToString(), out qtyFulfilled);
            decimal qtyOutstanding;

            decimal.TryParse(model.QuantityOutstanding.ToString(), out qtyOutstanding);

            if (listing != null)
            {
                listing.ItemDescription     = model.ItemDescription;
                listing.ItemCategory        = model.ItemCategory;
                listing.ItemType            = model.ItemType;
                listing.QuantityRequired    = qtyRequired;
                listing.QuantityFulfilled   = qtyFulfilled;
                listing.QuantityOutstanding = qtyOutstanding;
                listing.UoM                         = model.UoM;
                listing.RequiredFrom                = model.RequiredFrom;
                listing.RequiredTo                  = model.RequiredTo;
                listing.AcceptDamagedItems          = model.AcceptDamagedItems;
                listing.AcceptOutOfDateItems        = model.AcceptOutOfDateItems;
                listing.CollectionAvailable         = model.CollectionAvailable;
                listing.ListingStatus               = model.ListingStatus;
                listing.ListingOrganisationPostcode = model.ListingOrganisationPostcode;
                listing.RecordChange                = GeneralEnums.RecordChangeEnum.ListingStatusChange;
                listing.RecordChangeBy              = AppUserHelpers.GetAppUserIdFromUser(user);
                listing.RecordChangeOn              = DateTime.Now;

                db.Entry(listing).State = EntityState.Modified;
                db.SaveChanges();
            }

            return(listing);
        }
        public static List <UserAction> GetActionsForUser(ApplicationDbContext db, IPrincipal user)
        {
            List <UserAction> list = GetActionsForUser(db, AppUserHelpers.GetAppUserIdFromUser(user));

            return(list);
        }
Beispiel #22
0
        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);
        }
Beispiel #23
0
        public static Order UpdateOrderDates(ApplicationDbContext db, string type, Guid orderId, bool orderCollected, bool orderReceived, bool orderInClosed, bool orderDistributed, bool orderDelivered, bool orderOutClosed, IPrincipal user)
        {
            Order order            = OrderHelpers.GetOrder(db, orderId);
            Guid  currentAppUserId = AppUserHelpers.GetAppUserIdFromUser(user);

            if (type == "in")
            {
                if (orderCollected)
                {
                    order.OrderCollectedBy       = currentAppUserId;
                    order.OrderCollectedDateTime = DateTime.Now;
                    order.OrderInStatus          = OrderInStatusEnum.Collected;
                }
                if (orderReceived)
                {
                    order.OrderReceivedBy       = currentAppUserId;
                    order.OrderReceivedDateTime = DateTime.Now;
                    order.OrderInStatus         = OrderInStatusEnum.Received;
                }
                if (orderInClosed)
                {
                    order.OrderInClosedBy       = currentAppUserId;
                    order.OrderInClosedDateTime = DateTime.Now;
                    order.OrderInStatus         = OrderInStatusEnum.Closed;
                }

                db.Entry(order).State = EntityState.Modified;
                db.SaveChanges();

                //If order closed then add Action to Organisation of order out if they haven't closed their side yet saying this is closed  //LSLSLS

                //Organisation org = OrganisationHelpers.GetOrganisation(db, offer.OfferOriginatorOrganisationId);
                //UserActionHelpers.CreateUserAction(db, ActionTypeEnum.NewOrderReceived, "New order received from " + org.OrganisationName, offer.OfferId, appUser.AppUserId, org.OrganisationId, user);
            }

            if (type == "out")
            {
                if (orderDistributed)
                {
                    order.OrderDistributedBy        = currentAppUserId;
                    order.OrderDistributionDateTime = DateTime.Now;
                    order.OrderOutStatus            = OrderOutStatusEnum.Dispatched;
                }
                if (orderDelivered)
                {
                    order.OrderDeliveredBy       = currentAppUserId;
                    order.OrderDeliveredDateTime = DateTime.Now;
                    order.OrderOutStatus         = OrderOutStatusEnum.Delivered;
                }
                if (orderOutClosed)
                {
                    order.OrderOutClosedBy       = currentAppUserId;
                    order.OrderOutClosedDateTime = DateTime.Now;
                    order.OrderOutStatus         = OrderOutStatusEnum.Closed;
                }

                db.Entry(order).State = EntityState.Modified;
                db.SaveChanges();

                //If order closed then add Action to Organisation of order out if they haven't closed their side yet saying this is closed    //LSLSLS
            }

            return(order);
        }
Beispiel #24
0
        public static AppUserSettings GetAppUserSettingsForUser(ApplicationDbContext db, IPrincipal user)
        {
            AppUserSettings appUserSettings = GetAppUserSettingsForUser(db, AppUserHelpers.GetAppUserIdFromUser(user));

            return(appUserSettings);
        }