public async Task <IActionResult> Put(int id, [FromBody] ActionTargetViewModel actionTarget) { if (ModelState.IsValid) { try { ActionTarget _actionTarget = _unitOfWork.ActionTarget.GetSingleOrDefault(e => e.Id == actionTarget.Id); _actionTarget.Actions = _unitOfWork.Actions.GetSingleOrDefault(e => e.Id == actionTarget.ActionsId); _actionTarget.Group = actionTarget.GroupId == null ? _actionTarget.Group : _unitOfWork.Group.GetSingleOrDefault(e => e.Id == actionTarget.GroupId); _actionTarget.Target = actionTarget.Target; _unitOfWork.ActionTarget.Update(_actionTarget); await _unitOfWork.SaveChangesAsync(); return(Ok("OK")); } catch (Exception ex) { return(BadRequest(ex.Data)); } } else { return(BadRequest(ModelState)); } }
public async Task <IActionResult> Post([FromBody] ActionTargetViewModel actionTarget) { if (ModelState.IsValid) { try { ActionTarget _actionTarget = new ActionTarget(); _actionTarget.Actions = _unitOfWork.Actions.GetSingleOrDefault(e => e.Id == actionTarget.ActionsId); _unitOfWork.ActionTarget.Add(_actionTarget); await _unitOfWork.SaveChangesAsync(); return(Ok("OK")); } catch (Exception ex) { return(BadRequest(ex.Data)); } } else { return(BadRequest(ModelState)); } }