예제 #1
0
        public async Task Update(Typeservice obj)
        {
            bool hasAny = await _context.Typeservice.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);
            }
        }
        public async Task <IActionResult> Edit(int id, Typeservice typeservice)
        {
            if (id != typeservice.Id)
            {
                return(BadRequest());
            }
            try
            {
                await _typeserviceService.Update(typeservice);

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

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