public ActionResult <FarmFieldDto> Create(FarmFieldDto targetValue) { var userDimensions = targetValue.Dimensions; var dimensions = new Dimensions { }; dimensions.Width = userDimensions.Width; dimensions.Height = userDimensions.Height; dynamic farmfield = null; if (userDimensions != null) { farmfield = new FarmField { Name = targetValue.Name, Active = targetValue.Active, Dimensions = dimensions, Description = targetValue.Description }; } if (farmfield == null) { return(BadRequest("Farmfield is null, AHHHHHH")); } var data = context.Set <FarmField>().Add(farmfield); context.SaveChanges(); targetValue.Id = data.Entity.Id; return(Created($"/api/farm-field/{data.Entity.Id}", targetValue)); }
public ActionResult <FarmFieldDto> Create(FarmFieldDto targetValue) { var data = context.Set <FarmField>().Add(new FarmField { Name = targetValue.Name, Active = targetValue.Active, Dimensions = new Dimensions { Width = targetValue.Dimensions.Width, Height = targetValue.Dimensions.Height } }); context.SaveChanges(); targetValue.Id = data.Entity.Id; return(Created($"/api/farm-field/{data.Entity.Id}", targetValue)); }
public ActionResult <FarmFieldDto> Update(int id, FarmFieldDto targetValue) { var data = context.Set <FarmField>().FirstOrDefault(x => x.Id == id); if (data == null) { return(NotFound()); } data.Name = targetValue.Name; data.Active = targetValue.Active; data.Dimensions = new Dimensions { Width = targetValue.Dimensions.Width, Height = targetValue.Dimensions.Height }; data.Description = targetValue.Description; context.SaveChanges(); return(Ok()); }