public async Task <IActionResult> Create(string lawnId, LawnSectionForCreate newSection) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var section = await _lawnSectionService.Create(lawnId, newSection); return(CreatedAtAction(nameof(Get), new { lawnId = lawnId, sectionId = section.Id }, new LawnSection(section))); }
public async Task <Models.LawnSection> Create(string lawnId, LawnSectionForCreate newLawnSection) { var lawn = await GetLawnAsync(lawnId); var lawnSection = new Models.LawnSection { Id = ObjectId.GenerateNewId().ToString(), Name = newLawnSection.Name, Description = newLawnSection.Description, ImageUrl = newLawnSection.ImageUrl, SquareFeet = newLawnSection.SquareFeet, CreatedDate = DateTime.UtcNow, UpdatedDate = DateTime.UtcNow }; lawn.Sections.Add(lawnSection); await _lawns.ReplaceOneAsync(l => l.Id == lawnId, lawn); return(lawnSection); }