コード例 #1
0
        public async Task <IActionResult> GetPhysicalProperty([FromRoute] int id)
        {
            try
            {
                var item = await _dm.PhysicalPropertiesAccessor.GetPhysicalProperty(id);

                if (item == null)
                {
                    return(Ok(new ResponseModel()
                    {
                        Result = ResultCode.NotFound
                    }));
                }


                PhysicalPropertyViewModel model = item.ToPhysicalPropertyViewModel();

                return(Ok(model));
            }
            catch (Exception ex)
            {
                return(Ok(new ResponseModel()
                {
                    Result = ResultCode.ServerError, Description = ex.Message
                }));
            }
        }
コード例 #2
0
        public async Task <IActionResult> DeleteItem([FromBody] PhysicalPropertyViewModel model)
        {
            try
            {
                var item = await _dm.PhysicalPropertiesAccessor.GetPhysicalProperty(model.Id);

                if (item == null)
                {
                    return(Ok(new ResponseModel()
                    {
                        Result = ResultCode.NotFound
                    }));
                }

                await _dm.PhysicalPropertiesAccessor.DeletePhysicalPropertyItem(item.Id);

                return(Ok(new ResponseModel()
                {
                    Result = ResultCode.Success
                }));
            }
            catch (Exception ex)
            {
                return(Ok(new ResponseModel()
                {
                    Result = ResultCode.ServerError
                }));
            }
        }
コード例 #3
0
        public async Task <ResponseModel> DeleteGetPhysicalProperty(PhysicalPropertyViewModel model)
        {
            string uri     = "api/physicalproperty/Delete";
            var    request = await _http.PostAsJsonAsync <PhysicalPropertyViewModel>(uri, model);

            var response = await request.Content.ReadFromJsonAsync <ResponseModel>();

            return(response);
        }
        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);
        }
コード例 #5
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
                }));
            }
        }
        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);
        }