Exemplo n.º 1
0
        public JsonResult AddInfo(People person)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return Json(new { Result = "ERROR", Message = "Form is not valid! Please correct it and try again." });
                }

                _peoples.Add(person);
                return Json(new { Result = "OK", Record = _peoples.LastOrDefault() });
            }
            catch (Exception ex)
            {
                return Json(new { Result = "ERROR", Message = ex.Message });
            }
        }
Exemplo n.º 2
0
        public JsonResult UpdateInfo(People person)
        {
            try
            {
                person.DOB = Convert.ToDateTime(person.DOB);

                if (!ModelState.IsValid)
                {
                    return Json(new { Result = "ERROR", Message = "Form is not valid! Please correct it and try again." });
                }

                var info = _peoples.Find(x=>x.ID==person.ID);
                info.Name = person.Name;
                info.DOB = person.DOB;

                return Json(new { Result = "OK", Record = _peoples.LastOrDefault() });
            }
            catch (Exception ex)
            {
                return Json(new { Result = "ERROR", Message = ex.Message });
            }
        }