예제 #1
0
        public WorkshopDto Update(CreateWorkshopDto input)
        {
            var cityQuery = _cityRepository.GetAll().Where(c => c.CityName == input.CityName);
            var city      = cityQuery.FirstOrDefault();

            if (city.IsNullOrDeleted())
            {
                throw new ApplicationException("City不存在或输入错误");
            }

            var factoryQuery = _factoryRepository.GetAll().Where(f => f.FactoryName == input.FactoryName);
            var factory      = factoryQuery.FirstOrDefault();

            if (factory.IsNullOrDeleted())
            {
                throw new ApplicationException("Factory不存在或输入错误");
            }

            var workshop = _workshopRepository.Get(input.Id);

            ObjectMapper.Map(input, workshop);
            workshop.Factory = factory;
            var result = _workshopRepository.Update(workshop);

            CurrentUnitOfWork.SaveChanges();
            return(ObjectMapper.Map <WorkshopDto>(workshop));
        }
예제 #2
0
        public Object GetDeviceLocationByDeviceId(EntityDto <int> input)
        {
            var device = _deviceRepository.Get(input.Id);

            if (device.IsNullOrDeleted())
            {
                throw new ApplicationException("device不存在或已被删除");
            }
            var gateway  = _gatewayRepository.Get(device.GatewayId);
            var workshop = _workshopRepository.Get(gateway.WorkshopId);
            var factory  = _factoryRepository.Get(workshop.FactoryId);
            var city     = _cityRepository.Get(factory.CityId);

            if (city.IsNullOrDeleted())
            {
                throw new ApplicationException("city不存在或已被删除");
            }
            return(new
            {
                cityName = city.CityName,
                longitude = city.Longitude,
                latitude = city.Latitude,
                factoryName = factory.FactoryName,
                workshopName = workshop.WorkshopName,
                gatewayName = gateway.GatewayName
            });
        }