public ActionResult UpdateLink(Link link) { var response = new ResponseWithValidation(); JsonValidation.GetJsonWithValidation(ModelState, ref response); if (ModelState.IsValid) { _linkRepository.UpdateLink(link); } return(Json(JsonConvert.SerializeObject(response))); }
public ActionResult AddLink(Link link) { var response = new ResponseWithValidation(); JsonValidation.GetJsonWithValidation(ModelState, ref response); if (ModelState.IsValid) { Link addedLink = _linkRepository.AddLink(link); response.Data = addedLink; } return(Json(JsonConvert.SerializeObject(response))); }
public static void GetJsonWithValidation(ModelStateDictionary modelState, ref ResponseWithValidation response) { var errors = new List <ValidationError>(); if (!modelState.IsValid) { foreach (var key in modelState.Keys) { errors.AddRange(modelState[key].Errors.Select(error => new ValidationError { Key = key, Message = error.ErrorMessage })); } response.Errors.AddRange(errors); } }