public async Task <IActionResult> PutWidgets(int id, Widgets widgets) { if (id != widgets.Id) { return(BadRequest()); } _context.Entry(widgets).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!WidgetsExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PatchWidgets(int account_id, string uuid, [FromBody] JsonPatchDocument <Widgets> widgets) { if (widgets.Operations.Count != 0) { var widget = await _context.Widgets.Where(w => w.AccountId == account_id && String.Equals(w.UUID, uuid)).FirstOrDefaultAsync(); if (widget != null) { //var elementsWithPathPurpose = widgets.Operations.Where(o => o.path.Equals("Purpose")).FirstOrDefault(); //if (elementsWithPathPurpose != null) //{ // var _purpose = await _context.Purposes.Where(p => string.Equals(elementsWithPathPurpose.value.ToString(), p.Purpose, StringComparison.OrdinalIgnoreCase)).FirstOrDefaultAsync(); // if (_purpose != null && string.Equals(elementsWithPathPurpose.value.ToString(), _purpose.Purpose, StringComparison.OrdinalIgnoreCase)==false) // { // widgets.Replace(e=>e.PurposeId, _purpose.Id); // } //} widget.UpdatedTimeUTC = DateTime.UtcNow; widgets.ApplyTo(widget, ModelState); if (!ModelState.IsValid) { return(new BadRequestObjectResult(new { Success = false })); } _context.Entry(widget).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!WidgetsExists(account_id)) { return(NotFound(new { Success = false, Message = "Widget with supplied " + account_id + " is not Existed" })); } else { throw; } } } else { return(NotFound(new { Success = false, Message = "Widget Not Found" })); } return(Ok(new { Success = true, widget = widget })); } else { return(Ok(new { Success = false, Message = "No Operations/Values Specified For Patching" })); } }