public ActionResult Delete(Guid id) { try { // Get FarmBot FarmBot farmBotToRemove = _farmBotRepository.GetById(id); // Check if (farmBotToRemove == null) { return(NotFound()); } // Remove _farmBotRepository.Remove(farmBotToRemove); // Save _farmBotDbContext.SaveChanges(); // Return result return(NoContent()); } catch { return(BadRequest()); } }
public async Task UpdateAsync(FarmBot farmBot) { string url = $"{Endpoints.FarmBot}"; HttpResponseMessage httpResponeMessage = await _httpRequest.PutAsync(url, farmBot); httpResponeMessage.EnsureSuccessStatusCode(); }
public ActionResult <FarmBot> Get(Guid id) { // Get FarmBot FarmBot FarmBot = _farmBotRepository.FirstOrDefault(p => p.Id == id); // Check if (FarmBot == null) { return(NotFound()); } // Return result return(FarmBot); }
private async Task Add() { // FarmBot var farmBot = new FarmBot { Id = Globals.FarmBotId, Name = "Utm FarmBot", IpAddress = "192.168.1.1", IpCameraAddress = "192.168.1.1" }; await Globals.FarmBotService.AddAsync(farmBot); // Plant var plant = new Plant { Id = Globals.PlantId, Name = "Carot", Info = "Info", RowDistance = 25, PlantDistance = 25, SoilHumidity = 50, SeedDepth = 15, Duration = 30 }; await Globals.PlantService.AddAsync(plant); // Parameters var parameters = new Parameters { Id = Globals.ParametersId, FarmBotId = Globals.FarmBotId, AirTemperature = 15, Luminosity = 12, SoilHumidity = 15, }; await Globals.ParametersService.AddAsync(parameters); // Event var farmBotEvent = new Event { Id = Globals.EventId, Info = "0" }; await Globals.EventService.AddAsync(farmBotEvent); }
private static async Task GetFarmBot() { try { _farmBot = await _farmBotService .GetByIdAsync(TempData.FarmBotId); _lastX = _farmBot.LastX; _lastY = _farmBot.LastY; } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
private async Task Update() { // Plant Plant plant = await Globals.PlantService.GetByIdAsync(Globals.PlantId); Assert.NotNull(plant); await Globals.PlantService.UpdateAsync(plant); // FarmBot FarmBot farmBot = await Globals.FarmBotService.GetByIdAsync(Globals.FarmBotId); Assert.NotNull(farmBot); await Globals.FarmBotService.UpdateAsync(farmBot); }
public ActionResult Put([FromBody] FarmBot farmBot) { try { // Get FarmBot FarmBot farmBotToUpdate = _farmBotRepository.GetById(farmBot.Id); // Check if (farmBotToUpdate == null) { return(NotFound()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // Update farmBotToUpdate.IpAddress = farmBot.IpAddress; farmBotToUpdate.Name = farmBot.Name; farmBotToUpdate.IpCameraAddress = farmBot.IpCameraAddress; farmBotToUpdate.LastX = farmBot.LastX; farmBotToUpdate.LastY = farmBot.LastY; farmBotToUpdate.Width = farmBot.Width; farmBotToUpdate.Length = farmBot.Length; farmBotToUpdate.Updated = DateTime.Now; // Save _farmBotDbContext.SaveChanges(); // Return result return(NoContent()); } catch { return(BadRequest(ModelState)); } }
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)); } }