예제 #1
0
        public async Task Update(Legalperson obj)
        {
            bool hasAny = await _context.Legalperson.AnyAsync(x => x.Id == obj.Id);

            if (!hasAny)
            {
                throw new NotFoundException("Id not found");
            }
            try
            {
                _context.Update(obj);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException e)
            {
                throw new DbConcurrencyException(e.Message);
            }
        }
예제 #2
0
        public async Task <IActionResult> Edit(int id, Legalperson legalperson)
        {
            if (id != legalperson.Id)
            {
                return(BadRequest());
            }
            try
            {
                await _legalpersonService.Update(legalperson);

                return(RedirectToAction(nameof(Index)));
            }
            catch (NotFoundException)
            {
                return(NotFound());
            }
            catch (DbConcurrencyException)
            {
                return(BadRequest());
            }
        }
예제 #3
0
 public async Task InsertAsync(Legalperson legalperson)
 {
     _context.Add(legalperson);
     await _context.SaveChangesAsync();
 }
예제 #4
0
        public async Task <IActionResult> Create(Legalperson legalperson)
        {
            await _legalpersonService.InsertAsync(legalperson);

            return(RedirectToAction(nameof(Index)));
        }