Exemple #1
0
        public async Task <Response <ITest> > ChangeTest(ChangeTest change)
        {
            var response = new Response <ITest>();

            try
            {
                int id   = Convert.ToInt32(change.Id);
                var test = await _context.Test.Where(p => p.Id == id).FirstOrDefaultAsync();

                if (test == null)
                {
                    response.Error = new Error(404, "Test not found!");
                    return(response);
                }

                test.Name = change.Name;


                await _context.SaveChangesAsync();

                response.Data = test;
            }
            catch (Exception e)
            {
                response.Error = new Error(500, "Can`t shange test: " + e);
            }

            return(response);
        }
Exemple #2
0
        public async Task <IActionResult> ChangeTest([FromBody] ChangeTest test)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                var userInfo = await _testService.ChangeTest(test);

                if (userInfo.Error != null)
                {
                    return(StatusCode(userInfo.Error.ErrorCode, userInfo.Error.ErrorDescriprion));
                }

                return(Ok(userInfo.Data));
            }
            catch (Exception e)
            {
                return(StatusCode(500, new Error(e.Message)));
            }
        }