示例#1
0
        public void ClearClientFarmFieldData()
        {
            //delete
            var fieldRepo  = new FieldRepository(_context);
            var farmRepo   = new FarmRepository(_context);
            var clientRepo = new ClientRepository(_context);

            var allFields = fieldRepo.GetAll();

            fieldRepo.BulkDelete(allFields);

            var allFarms = farmRepo.GetAll();

            farmRepo.BulkDelete(allFarms);

            var allClients = clientRepo.GetAll();

            clientRepo.BulkDelete(allClients);

            _context.SaveChanges();
        }
示例#2
0
        public string GetListIDWithSerialNumber(string serial, double lat, double lng, PickupListDestination dest)
        {
            var result = _context.PickupLists.Include("AssignedModules").FirstOrDefault(p => p.AssignedModules.Any(m => m.Name == serial) && p.Destination == dest);
            var module = _context.Modules.Include("Field.Farm.Client").SingleOrDefault(m => m.Name == serial);

            if (result != null)
            {
                return(result.Id);
            }

            //if unassigned list already exists just return it
            result = _context.PickupLists.Include("AssignedModules").FirstOrDefault(p => p.Id == GUIDS.UNASSIGNED_LIST_ID);

            if (result != null)
            {
                return(result.Id);
            }


            var settingsRepo       = new SettingsRepository(_context);
            var syncedSettingsRepo = new SyncedSettingRepository(_context);
            var syncedSettings     = syncedSettingsRepo.GetAll().FirstOrDefault();
            var fieldRepo          = new FieldRepository(_context);
            var farmRepo           = new FarmRepository(_context);
            var clientRepo         = new ClientRepository(_context);

            var truck = settingsRepo.GetCurrentTruck();


            ClientEntity client = null;
            FarmEntity   farm   = null;
            FieldEntity  field  = null;

            if (module == null) //if no module already exists then create an un-assigned list
            {
                client = clientRepo.GetById(GUIDS.UNASSIGNED_CLIENT_ID);

                if (client == null)
                {
                    client         = new ClientEntity();
                    client.Id      = GUIDS.UNASSIGNED_CLIENT_ID;
                    client.Name    = "Unassigned";
                    client.Created = DateTime.UtcNow;
                    client.Source  = InputSource.TRUCK;
                    _context.Clients.Add(client);
                }

                farm = farmRepo.GetById(GUIDS.UNASSIGNED_FARM_ID);
                if (farm == null)
                {
                    farm               = new FarmEntity();
                    farm.Id            = GUIDS.UNASSIGNED_FARM_ID;
                    farm.ClientId      = client.Id;
                    farm.SyncedToCloud = true;
                    farm.Source        = InputSource.TRUCK;
                    farm.Name          = "Unassigned";
                    farm.Created       = DateTime.UtcNow;
                    _context.Farms.Add(farm);
                }

                field = fieldRepo.GetById(GUIDS.UNASSIGNED_FIELD_ID);
                if (field == null)
                {
                    field               = new FieldEntity();
                    field.Id            = GUIDS.UNASSIGNED_FIELD_ID;
                    field.FarmId        = farm.Id;
                    field.SyncedToCloud = true;
                    field.Source        = InputSource.TRUCK;
                    field.Name          = "Unassigned";
                    field.Created       = DateTime.UtcNow;
                    _context.Fields.Add(field);
                }
            }
            else
            {
                client = module.Field.Farm.Client;
                farm   = module.Field.Farm;
                field  = module.Field;
            }

            PickupListEntity list = new PickupListEntity();

            list.Id                 = GUIDS.UNASSIGNED_LIST_ID;
            list.Latitude           = lat;
            list.Longitude          = lng;
            list.Source             = InputSource.TRUCK;
            list.ModulesPerLoad     = (syncedSettings != null) ? syncedSettings.ModulesPerLoad : 4;
            list.FieldId            = field.Id;
            list.Name               = "Unassigned";
            list.PickupListStatus   = PickupListStatus.OPEN;
            list.SyncedToCloud      = true;
            list.Created            = DateTime.UtcNow;
            list.AssignedTrucks     = new List <TruckEntity>();
            list.DownloadedToTrucks = new List <TruckEntity>();
            list.Destination        = dest;
            list.AssignedTrucks.Add(truck);
            list.DownloadedToTrucks.Add(truck);
            _context.PickupLists.Add(list);
            _context.SaveChanges();
            //List<string> serialsToMove = new List<string>();
            //serialsToMove.Add(serial);
            //this.MoveModulesToList(list, serialsToMove);
            return(list.Id);
        }