public async Task <IActionResult> PutSimtest(int id, UpdateTestModel model)
        {
            if (id != model.TestId)
            {
                return(BadRequest());
            }
            // map model to entity
            var simtest = _mapper.Map <Simtest>(model);

            _context.Entry(simtest).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SimtestExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #2
0
        public bool SaveTestModel(UpdateTestModel model)
        {
            var result = true;

            using (var context = _testRepository.GetDbContext())
            {
                using (var trans = context.Database.BeginTransaction())
                {
                    try
                    {
                        if (!model.Id.HasValue)
                        {
                            var modelAdd = new TestThu {
                                Name = model.Name
                            };
                            _testRepository.Insert(modelAdd);
                        }
                        else
                        {
                            _testRepository.Update(new TestThu {
                                Id = model.Id.Value, Name = model.Name
                            });
                        }
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();
                        throw ex;
                    }
                    trans.Commit();
                }
            }
            return(result);
            //using (var context = new AppDbContext())
            //{

            //}
        }
        public IActionResult UpdateTest([FromBody] UpdateTestModel model)
        {
            var result = _testService.SaveTestModel(model);

            return(Json(new { success = result }));
        }