Exemplo n.º 1
0
        //public void Post([FromBody] string value)
        //{
        //}
        public IActionResult Post([FromBody] Registration obj)
        {
            // create the object of context

            var context = new ValidationContext(obj, null, null);

            //if there are errors then it will fill in ValidationResult collection

            var result = new List <ValidationResult>();

            //class says that validate the obj and if there is error then fill in result

            var isValid = Validator.TryValidateObject(obj, context, result, true);

            if (result.Count == 0)
            {
                PatientDAL dal = new PatientDAL();
                dal.Database.EnsureCreated(); // ensure table is created or not
                dal.Add(obj);                 // here obj is UI comming object //it adds in memory not in database
                dal.SaveChanges();            // pysical commit save to database


                // return Json(recs);

                return(StatusCode(200, result)); // 200 for success
            }
            else
            {
                return(StatusCode(500, result)); // 500 for internal server error
            }
        }
        //  public void Post([FromBody] string value)
        // {
        // }


        public IActionResult Post([FromBody] PatientModel obj)
        {
            // create the object of context

            var context = new ValidationContext(obj, null, null);

            //if there are errors then it will fill in ValidationResult collection

            var result = new List <ValidationResult>();

            //class says that validate the obj and if there is error then fill in result

            var isValid = Validator.TryValidateObject(obj, context, result, true);

            if (result.Count == 0)
            {
                PatientDAL dal = new PatientDAL();
                dal.Database.EnsureCreated(); // ensure table is created or not
                dal.Add(obj);                 // here obj is UI comming object //it adds in memory not in database
                dal.SaveChanges();            // pysical commit save to database


                // List<PatientModel> recs = dal.PatientModels.
                //     Include("problems").ToList();
                List <PatientModel> recs = dal.PatientModels.
                                           Include(x => x.problems).
                                           ToList();
                List <Problem> patientProb = dal.Problems.ToList();


                var pat = new PatientModel
                {
                    problems = new List <Problem>()
                };


                //recs.Add(pat);


                return(StatusCode(200, recs)); // 200 for success
                // return Ok(recs);
            }
            else
            {
                return(StatusCode(500, result)); // 500 for internal server error
            }
        }
        public string Post([FromBody] PatientModel obj)
        {
            var context = new ValidationContext(obj, null, null);
            //fill the errors

            var result = new List <ValidationResult>();

            var isValid = Validator.TryValidateObject(obj, context, result, true);

            if (result.Count == 0)
            {
                PatientDAL dal = new PatientDAL(ConStr);
                dal.Database.EnsureCreated();   // ensure table is created or not
                dal.Add(obj);                   //inmemory
                dal.SaveChanges();              // pysical commit save to database


                List <PatientModel> recs = dal.PatientModels.Include(pat => pat.problems).
                                           ToList <PatientModel>();
                //List<DiseaseModel> dic = dal.Diseas.ToList<DiseaseModel>();
                //dynamic dics = new ExpandoObject();
                //dics.PatientModel = recs;
                //dics.DiseaseModel = dic;


                var json = JsonConvert.SerializeObject(recs, Formatting.None,
                                                       new JsonSerializerSettings()
                {
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                });
                return(json);

                // return StatusCode(200, recs);
            }
            else
            {
                var json = JsonConvert.SerializeObject(result, Formatting.None,
                                                       new JsonSerializerSettings()
                {
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                });
                // return StatusCode(500, result);
                return(json);
            }
        }
        public IActionResult Post([FromBody] DiseaseModel obj)
        {
            var context = new ValidationContext(obj, null, null);

            var result = new List <ValidationResult>();

            var isValid = Validator.TryValidateObject(obj, context, result, true);

            if (result.Count == 0)
            {
                PatientDAL dal = new PatientDAL(ConStr);
                dal.Database.EnsureCreated();   // ensure table is created or not
                dal.Add(obj);                   //inmemory
                dal.SaveChanges();              // pysical commit save to database
                List <DiseaseModel> recs = dal.Diseas.ToList();
                return(StatusCode(200, recs));
            }
            else
            {
                return(StatusCode(500, result));
            }
        }