Ejemplo n.º 1
0
        public TestSubTable Add(TestSubTable testSubTable)
        {
            // Pretend description is required
            if (string.IsNullOrEmpty(testSubTable.Testsubdescription))
            {
                throw new InvalidInputException("Required field missing.");
            }

            _context.Add(testSubTable);
            _context.SaveChanges();

            return(testSubTable);
        }
Ejemplo n.º 2
0
        public void Update(TestSubTable testSubTable)
        {
            var existingSubTable = _context.TestSubTable.Find(testSubTable.Testsubid);

            if (existingSubTable == null)
            {
                throw new ItemNotFoundException($"TestSubTable {testSubTable.Testsubid} not found.");
            }
            if (string.IsNullOrEmpty(testSubTable.Testsubdescription))
            {
                throw new InvalidInputException("Required field missing.");
            }

            existingSubTable.Testsubdescription = testSubTable.Testsubdescription;
            existingSubTable.Testsubdate        = testSubTable.Testsubdate;

            _context.TestSubTable.Update(existingSubTable);
            _context.SaveChanges();
        }
Ejemplo n.º 3
0
        public ActionResult Update([FromBody] TestSubTable testSubTable)
        {
            try
            {
                _testSubService.Update(testSubTable);
                return(NoContent());
            }
            catch (Exception ex)
            {
                if (ex is ItemNotFoundException)
                {
                    return(NotFound());
                }
                else if (ex is InvalidInputException)
                {
                    return(BadRequest());
                }

                return(StatusCode(500));
            }
        }
Ejemplo n.º 4
0
        public ActionResult AddSubTable([FromBody] TestSubTable testSubTable)
        {
            try
            {
                _testSubService.Add(testSubTable);
                return(CreatedAtAction("GetSubTable", new { id = testSubTable.Testid }, testSubTable));
            }
            catch (Exception ex)
            {
                if (ex is ItemNotFoundException)
                {
                    return(NotFound());
                }
                else if (ex is InvalidInputException)
                {
                    return(BadRequest());
                }

                return(StatusCode(500));
            }
        }