Exemplo n.º 1
0
        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)));
        }
Exemplo n.º 2
0
        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)));
        }
Exemplo n.º 3
0
        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);
            }
        }