public async Task <IActionResult> PutGoalPropertyValue(int id, [FromForm] GoalPropertyUpsert obj) { if (id != obj.ID) { return(BadRequest()); } GoalPropertyValue goalPropertyValue = new GoalPropertyValue() { GoalPropertyID = obj.GoalPropertyID, ID = obj.ID, Name = obj.Name }; _context.Entry(new GoalDetail() { ID = obj.GoalDetailID, GoalPropertyID = obj.GoalPropertyID, GoalID = obj.GoalID }).State = EntityState.Modified; _context.Entry(goalPropertyValue).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GoalPropertyValueExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <GoalPropertyValue> > PostGoalPropertyValue([FromForm] GoalPropertyUpsert obj) { var check = _context.GoalDetail.FirstOrDefault(x => x.GoalID == obj.GoalID && x.GoalPropertyID == obj.GoalPropertyID); if (check == null) { _context.GoalDetail.Add(new GoalDetail() { GoalID = obj.GoalID, GoalPropertyID = obj.GoalPropertyID }); } GoalPropertyValue goalPropertyValue = new GoalPropertyValue() { GoalPropertyID = obj.GoalPropertyID, Name = obj.Name }; _context.GoalPropertyValue.Add(goalPropertyValue); await _context.SaveChangesAsync(); return(CreatedAtAction("GetGoalPropertyValue", new { id = goalPropertyValue.ID }, goalPropertyValue)); }