public async Task <object> EditChildren(ChildrenRequest model) { if (!ModelState.IsValid) { return(JsonResults.Error(400, ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage.ToString())); } try { var children = await _childrenService.GetChildren(model.Id); if (children == null) { return(JsonResults.Error(404, "It`s children center not found")); } children.FirstName = model.FirstName; children.LastName = model.LastName; children.DateOfBirth = model.DateOfBirth; await _childrenService.UpdateChildren(children); return(JsonResults.Success()); } catch (Exception ex) { return(JsonResults.Error(400, ex.Message)); } }
public async Task <object> AddChildren(ChildrenRequest request) { if (!ModelState.IsValid) { return(JsonResults.Error(400, ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage.ToString())); } try { var model = new Children { FirstName = request.FirstName, LastName = request.LastName, DateOfBirth = request.DateOfBirth, UserId = request.UserId }; await _childrenService.AddChildren(model); return(JsonResults.Success()); } catch (Exception ex) { return(JsonResults.Error(400, ex.Message)); } }