コード例 #1
0
ファイル: PlantController.cs プロジェクト: amtisian/farm_bot
        public async Task <ActionResult <Plant> > Post([FromBody] Plant plant)
        {
            try
            {
                // Check model
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                // Add
                _plantRepository.Add(plant);

                // Save
                _farmBotDbContext.SaveChanges();

                // Notify
                //await _communicationHubContext.Clients.All.ReceiveMessage("", $"{plant.Name} plant created");

                // Return result
                return(CreatedAtAction(nameof(Get), plant));
            }
            catch
            {
                return(BadRequest(ModelState));
            }
        }
コード例 #2
0
        public ActionResult<Event> Post([FromBody] FarmBotPlant farmBotPlant)
        {
            try
            {
                // Check model
                if (!ModelState.IsValid)
                    return BadRequest(ModelState);

                // Add
                _farmBotPlantsRepository.Add(farmBotPlant);

                // Save
                _farmBotDbContext.SaveChanges();

                // Return result
                return CreatedAtAction(nameof(Get), farmBotPlant);
            }
            catch
            {
                return BadRequest(ModelState);
            }
        }
コード例 #3
0
        public ActionResult <Parameters> Post([FromBody] Parameters parameters)
        {
            try
            {
                // Check model
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                // Add
                _parametersRepository.Add(parameters);

                // Save
                _farmBotDbContext.SaveChanges();

                // Return result
                return(CreatedAtAction(nameof(Get), parameters));
            }
            catch
            {
                return(BadRequest(ModelState));
            }
        }
コード例 #4
0
        public ActionResult <Event> Post([FromBody] Event farmBotEvent)
        {
            try
            {
                // Check model
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                // Add
                _eventRepository.Add(farmBotEvent);

                // Save
                _farmBotDbContext.SaveChanges();

                // Return result
                return(CreatedAtAction(nameof(Get), new { id = farmBotEvent.Id }, farmBotEvent));
            }
            catch
            {
                return(BadRequest(ModelState));
            }
        }
コード例 #5
0
        public ActionResult <FarmBot> Post([FromBody] FarmBot FarmBot)
        {
            try
            {
                // Check model
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                // Add
                _farmBotRepository.Add(FarmBot);

                // Save
                _farmBotDbContext.SaveChanges();

                // Return result
                return(CreatedAtAction(nameof(Get), FarmBot));
            }
            catch
            {
                return(BadRequest(ModelState));
            }
        }