Ejemplo n.º 1
0
        public object AddTest(testTab test)
        {
            var result = db.testTabs.Where(s => s.tstName == test.tstName && s.cId == test.cId && s.subId == test.subId && s.aId == test.aId).FirstOrDefault();


            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                if (result == null)
                {
                    db.testTabs.Add(new testTab()
                    {
                        tstName = test.tstName,
                        cId     = test.cId,
                        subId   = test.subId,
                        aId     = test.aId
                    });
                    int x = db.SaveChanges();
                    return(x);
                }
                else
                {
                    return("Exists");
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 2
0
        public object EditTest(testTab test)
        {
            var result = db.testTabs.Where(s => s.tstId == test.tstId && s.tstName == test.tstName && s.cId == test.cId && s.subId == test.subId).FirstOrDefault();


            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                testTab objTest = db.testTabs.Find(test.tstId);
                if (result == null)
                {
                    if (objTest != null)
                    {
                        objTest.tstName = test.tstName;
                        objTest.cId     = test.cId;
                        objTest.subId   = test.subId;
                    }
                    else
                    {
                        return("Not Found");
                    }
                    int i = this.db.SaveChanges();
                    return(i);
                }
                else
                {
                    return("Exists");
                }
            }
            catch (Exception)
            {
                throw;
            }
        }