public static PhysicalPropertyViewModel ToPhysicalPropertyViewModel(this PhysicalPropertyEntity entity)
        {
            PhysicalPropertyViewModel model = new PhysicalPropertyViewModel();

            model.Id          = entity.Id;
            model.Temperature = entity.Temperature;
            model.Humidity    = entity.Humidity;

            model.Name = "Temperature: " + entity.Temperature.ToString() + ", Humidity: " + entity.Humidity.ToString();
            return(model);
        }
コード例 #2
0
        public async Task <IActionResult> Save([FromBody] PhysicalPropertyViewModel model)
        {
            try
            {
                PhysicalPropertyEntity entity = null;
                if (!ModelState.IsValid)
                {
                    return(Ok(new ResponseModel()
                    {
                        Result = ResultCode.NotValidData
                    }));
                }
                var item = await _dm.PhysicalPropertiesAccessor.GetPhysicalProperty(model.Humidity, model.Temperature);

                if (item != null && item.Id != model.Id)
                {
                    return(Ok(new ResponseModel()
                    {
                        Result = ResultCode.AlreadyExists
                    }));
                }
                if (model.Id <= 0)
                {
                    entity = new PhysicalPropertyEntity();
                }
                else
                {
                    entity = await _dm.PhysicalPropertiesAccessor.GetPhysicalProperty(model.Id);

                    if (entity == null)
                    {
                        return(Ok(new ResponseModel()
                        {
                            Result = ResultCode.AlreadyExists
                        }));
                    }
                }
                var entityToSave = model.ToPhysicalPropertyEntity();

                await _dm.PhysicalPropertiesAccessor.SavePhysicalProperty(entityToSave);

                return(Ok(new ResponseModel()
                {
                    Result = ResultCode.Success
                }));
            }
            catch (Exception ex)
            {
                return(Ok(new ResponseModel()
                {
                    Result = ResultCode.ServerError, Description = ex.Message
                }));
            }
        }
コード例 #3
0
        public static PhysicalProperty ToPhysicalProperty(this PhysicalPropertyEntity newEntity, PhysicalProperty oldEntity = null)
        {
            PhysicalProperty entity = oldEntity;

            if (entity == null)
            {
                entity = new PhysicalProperty();
            }
            entity.Humidity    = newEntity.Humidity;
            entity.Temperature = newEntity.Temperature;

            return(entity);
        }
        public static PhysicalPropertyEntity ToPhysicalPropertyEntity(this PhysicalPropertyViewModel model)
        {
            PhysicalPropertyEntity entity = new PhysicalPropertyEntity();

            if (model.Id > 0)
            {
                entity.Id = model.Id;
            }
            entity.Humidity    = model.Humidity;
            entity.Temperature = model.Temperature;

            return(entity);
        }
コード例 #5
0
        public async Task <PhysicalPropertyEntity> SavePhysicalProperty(PhysicalPropertyEntity entity)
        {
            var _item = await Query.Where(e => e.Id == entity.Id).FirstOrDefaultAsync();

            if (_item == null)
            {
                _item = (await SaveEntity(entity.ToPhysicalProperty(null)));
            }
            else
            {
                _item = (await SaveEntity(entity.ToPhysicalProperty(_item)));
            }
            return(await GetPhysicalProperty(_item.Id));
        }
コード例 #6
0
        public static PhysicalPropertyEntity ToPhysicalPropertyEntity(this PhysicalProperty model)
        {
            if (model == null)
            {
                return(null);
            }

            PhysicalPropertyEntity entity = new PhysicalPropertyEntity();

            entity.Id          = model.Id;
            entity.Humidity    = model.Humidity;
            entity.Temperature = model.Temperature;

            return(entity);
        }