Пример #1
0
        public async Task<Vehicle> Add(Vehicle item)
        {
            var newVeh = new Vehicle
            {
                IdCar = await IdCarExist(item.IdCar),
                HdId = await HdExist(item.HdId)
            };

            if (item.LicensePlate != null) 
                newVeh.LicensePlate = await LpExist(item.LicensePlate);
            if (item.LicensePlateType != null) 
                newVeh.LicensePlateType = await LpTypeExist(item.LicensePlateType.Value);
            if (item.LicensePlateAt != null) 
                newVeh.LicensePlateAt = await LpAtExist(item.LicensePlateAt.Value);
            if (item.ModelCarId != null) 
                newVeh.ModelCarId = await ModelExist(item.ModelCarId.Value);
            if (item.ColorCarId != null) 
                newVeh.ColorCarId = await ColorExist(item.ColorCarId.Value);
            if (item.OganizeCarId != null) 
                newVeh.OganizeCarId = await OgnExist(item.OganizeCarId.Value);
            if (item.BodyNo != null) 
                newVeh.BodyNo = await BodyNoExist(item.BodyNo);

            newVeh = _db.Vehicles.Add(newVeh);
            try
            {
                await _db.SaveChangesAsync();

                //add universe
                var newUn = new Universe
                {
                    VehicleId = newVeh.Id,
                    DisplayStatus = 2
                };
                _db.Universes.Add(newUn);
                try
                {
                    await _db.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException exception)
                {
                    throw new DbUpdateConcurrencyException(exception.Message);
                }

                return newVeh;
            }
            catch (DbUpdateConcurrencyException exception)
            {
                throw new DbUpdateConcurrencyException(exception.Message);
            }
        }
Пример #2
0
        public async Task<bool> UpdateData(Universe item)
        {
            if (item.CorrectDataId == null) throw new ArgumentNullException("CorrectDataId", "CorrectDataId is Required for this state");
            if (item.FuelLevel == null) throw new ArgumentNullException("FuelLevel", "FuelLevel is Required for this state");
            if (item.TempLevel == null) throw new ArgumentNullException("TempLevel", "TempLevel is Required for this state");
            if (item.Speed == null) throw new ArgumentNullException("Speed", "Speed is Required for this state");
            if (item.Direction == null) throw new ArgumentNullException("Speed", "Speed is Required for this state");
            if (string.IsNullOrEmpty(item.IpGps)) throw new ArgumentNullException("IpGps", "IpGps is Required for this state");
            if (item.Port == null) throw new ArgumentNullException("Port", "Port is Required for this state");
            if (item.LongGoogle == null) throw new ArgumentNullException("LongGoogle", "LongGoogle is Required for this state");
            if (item.LaGoogle == null) throw new ArgumentNullException("LaGoogle", "LaGoogle is Required for this state");

            var un = await IdExist(item.Id);
            un.CurrentDataDatetime = DateTime.UtcNow;
            un.CorrectDataId = item.CorrectDataId.Value;
            un.CorrectDataDatetime = item.CorrectDataDatetime;

            un.CmCommand = await CommExist(item.CmCommand);
            un.CmEngine = await EngineExist(item.CmEngine);
            un.CmMeter = await MeterExist(item.CmMeter);
            un.CmBatt = await BattExist(item.CmBatt);
            un.FuelLevel = item.FuelLevel.Value;
            un.CmTemp = await TempExist(item.CmTemp);
            un.TempLevel = item.TempLevel.Value;
            un.CmGps = await GpsExist(item.CmGps);
            un.Speed = item.Speed.Value;
            un.Direction = item.Direction.Value;
            un.LongGoogle = item.LongGoogle.Value;
            un.LaGoogle = item.LaGoogle.Value;
            //f*g
            un.CmSignalStatus = await SignalExist(item.CmSignalStatus);

            un.IpGps = item.IpGps;
            un.Port = item.Port.Value;

            _db.Entry(un).State = EntityState.Modified;
            try
            {
                await _db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException exception)
            {
                throw new DbUpdateConcurrencyException(exception.Message);
            }

            return true;
        }
Пример #3
0
        public async Task<bool> UpdateGps(Universe item)
        {
            if (item.GpsProductId == null) throw new ArgumentNullException("GpsProductId", "GpsProductId is Required for this state");

            var un = await IdExist(item.Id);
            un.GpsProductId = await ProductExist(item.GpsProductId.Value);
            if (item.OrderId != null) un.OrderId = await OrderExist(item.OrderId.Value);
            if (item.FixOrderId != null) un.FixOrderId = await FixExist(item.FixOrderId.Value);

            _db.Entry(un).State = EntityState.Modified;
            try
            {
                await _db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException exception)
            {
                throw new DbUpdateConcurrencyException(exception.Message);
            }

            return true;
        }
Пример #4
0
        private async Task<bool> AddVehicle(int quantity,short hdId,int orderId)
        {
            var car = _db.Vehicles.Where(c => c.HdId == hdId);//.Max(c => c.IdCar);

            //New HD and New Vehicle ... start at "000001"
            var maxIdCar = "0";
            //add New vehicle to current hd ... start at max idcar + 1
            if (car.Any()) maxIdCar = car.Max(c => c.IdCar);

            var max = Convert.ToInt32(maxIdCar);

            for (var i = 0; i < quantity; i++)
            {
                max = max + 1;

                var newVeh = new Vehicle
                {
                    IdCar = max.ToString("D6"),
                    HdId = hdId
                };

                newVeh = _db.Vehicles.Add(newVeh);
                try
                {
                    await _db.SaveChangesAsync();

                    //add universe
                    var newUn = new Universe
                    {
                        VehicleId = newVeh.Id,
                        OrderId = orderId,
                        DisplayStatus = 2//test
                    };
                    _db.Universes.Add(newUn);
                    try
                    {
                        await _db.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException exception)
                    {
                        throw new DbUpdateConcurrencyException(exception.Message);
                    }
                }
                catch (DbUpdateConcurrencyException exception)
                {
                    throw new DbUpdateConcurrencyException(exception.Message);
                }
            }

            return true;
        }