Exemplo n.º 1
0
        public static bool TryGetUserCustomers(string UserId, out IEnumerable <Customer> returnValue)
        {
            returnValue = null;

            // TODO: This method needs to be re-written as users can have multiple customers belonging to a combination of different companies from
            var ef = new Helpers.EF.DBEntities();

            // If associated companies are not all IH then exit and use legacy DAL
            if (ef.UserCompanies.Any(i => i.UserId == UserId && i.DatabaseName != DataBases.NetsuiteInsphire))
            {
                return(false);
            }

            using (var database = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString))
            {
                returnValue = database.QueryAsync <Customer>(
                    "web.GetUserCustomers" + DataBases.NetsuiteInsphire,
                    new { userid = UserId },
                    commandType: CommandType.StoredProcedure).Result;

                var customersInspHire = Helpers.InspHire.API.GetJoin(
                    "customers",
                    returnValue,
                    (Customer innerItem) => (innerItem.InspHireAcct),
                    "ACCT",
                    (innerItem, outerItem) => { innerItem.populate_InspHireCustomer(outerItem); }
                    );
            }

            return(true);
        }
Exemplo n.º 2
0
        internal static IEnumerable <MachineNotInUseInfo> GetMachinesNotInUse(string databaseName, Customer customer, string daysNotInUse)
        {
            // Get track unit data for all machines not being used
            int daysNotInUse_Int = int.Parse(daysNotInUse);

            // If weekend then only look at machines not in use before weekend started
            if (DateTime.Now.DayOfWeek == DayOfWeek.Saturday)
            {
                daysNotInUse_Int += 1;
            }
            else if (DateTime.Now.DayOfWeek == DayOfWeek.Sunday)
            {
                daysNotInUse_Int += 2;
            }

            // Get rented machines
            IEnumerable <RentalOrder> contractItems = GetRentalOrders(customer, DateTime.MinValue, DateTime.MaxValue);

            List <MachineNotInUseInfo> machines = new List <MachineNotInUseInfo>();
            Dictionary <string, MachineNotInUseInfo> machines_OnSerial = new Dictionary <string, MachineNotInUseInfo>();

            foreach (var item in contractItems)
            {
                MachineNotInUseInfo machine = new MachineNotInUseInfo();
                machine.populate_RentalOrder(item);
                machines.Add(machine);
                if (!string.IsNullOrEmpty(machine.ObjectId) && !machines_OnSerial.ContainsKey(machine.ObjectId))
                {
                    machines_OnSerial.Add(machine.ObjectId, machine);
                }
            }

            var machine_References = machines.Select(i => i.ObjectId);

            // Join with info track data infor from DB
            var      dbEntities          = new Helpers.EF.DBEntities();
            DateTime minActivityDateTime = DateTime.Now.AddDays(-daysNotInUse_Int);
            DateTime minGPSFixTime       = DateTime.Now.AddHours(-4);

            machines = dbEntities.TrackUnitDatas.Where(i =>
                                                       i.DateTimeStamp > minActivityDateTime &&
                                                       i.GpsFixTime > minGPSFixTime &&
                                                       machine_References.Contains(i.ReferenceNumber)
                                                       ).ToList()
                       .Join(
                machines,
                i1 => i1.ReferenceNumber,
                i2 => i2.ObjectId,
                (i1, i2) => i2
                )
                       .ToList();

            // Add information to

            return(machines);
        }
        internal void populate_CompanyDefaults(string companyId)
        {
            Helpers.EF.DBEntities   dbEntities = new Helpers.EF.DBEntities();
            Helpers.EF.RiwalCompany company    = dbEntities.RiwalCompanies.First(i => i.CompanyId == companyId);

            DataAreaId    = "-1";
            EmplId        = "-1";
            AccMgrName    = company.CompanyName;
            Email         = company.ContactEmailAddress;
            CellularPhone = company.ContactPhoneNumber;
        }