Exemple #1
0
        public void A_Post()
        {
            RestController api = new RestController(GetConnectionString());

            AgeRanger ar1 = new AgeRanger()
            {
                FirstName = "Test", LastName = "One", Age = 10
            };
            AgeRanger ar2 = new AgeRanger()
            {
                FirstName = "Test", LastName = "Two", Age = 20
            };

            ApplicationResultRecord result1 = api.Post(ar1);

            Assert.IsTrue(result1.Success);
            Assert.IsNotNull(result1.Record);
            Assert.IsTrue(result1.Record.ID > 0);

            ApplicationResultRecord result2 = api.Post(ar2);

            Assert.IsTrue(result2.Success);
            Assert.IsNotNull(result2.Record);
            Assert.IsTrue(result2.Record.ID > 0);
        }
Exemple #2
0
        public ApplicationResultRecord Post([FromBody] AgeRanger value)
        {
            ApplicationResultRecord result = null;

            try
            {
                string error = _Storage.Save(ref value);
                if (string.IsNullOrEmpty(error))
                {
                    result = new ApplicationResultRecord(value);
                }
                else
                {
                    result = new ApplicationResultRecord(error, null);
                }
            }
            catch (Exception ex)
            {
                result = new ApplicationResultRecord("Fail to save record!", ex);
            }

            return(result);
        }