Пример #1
0
        public async Task <IActionResult> PutEmployee(long id, Employee employee)
        {
            if (id != employee.Idemployee)
            {
                return(BadRequest());
            }

            _context.Entry(employee).State = efcore.EntityState.Modified;

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

            return(NoContent());
        }
Пример #2
0
        public async Task <IActionResult> PutDepartment(long id, DBDepartment department)
        {
            if (id != department.Iddepartment)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Пример #3
0
        //Shoud return maybe the success or failure of operation
        public async Task <int> AddDepartment(Department department)
        {
            using (var transaction = _context.Database.BeginTransactionAsync())
            {
                try
                {
                    _context.Department.Add(department);
                    await _context.SaveChangesAsync();

                    await transaction.Result.CommitAsync();
                }
                catch (Exception ex)
                {
                    await transaction.Result.RollbackAsync();

                    throw ex;
                }
            }
            return(-1);// never do that. :)
        }
Пример #4
0
 //Shoud return maybe the success or failure of operation
 public async Task <int> AddDepartment(Department department)
 {
     _context.Department.Add(department);
     return(await _context.SaveChangesAsync());
 }