예제 #1
0
        public async Task <bool> UpdateUser(Guid?id, User userToUpdate)
        {
            try
            {
                var user = await _taskDB.User.Where(e => e.RowId == id).FirstOrDefaultAsync();

                if (user != null)
                {
                    user.FirstName   = userToUpdate.FirstName;
                    user.LastName    = userToUpdate.LastName;
                    user.Address     = userToUpdate.Address;
                    user.Country     = userToUpdate.Country;
                    user.Description = userToUpdate.Description;
                    user.RDepartment = userToUpdate.RDepartment;

                    _taskDB.Attach(user);
                    _taskDB.Entry(user).Property(e => e.FirstName).IsModified   = true;
                    _taskDB.Entry(user).Property(e => e.LastName).IsModified    = true;
                    _taskDB.Entry(user).Property(e => e.Address).IsModified     = true;
                    _taskDB.Entry(user).Property(e => e.Country).IsModified     = true;
                    _taskDB.Entry(user).Property(e => e.Description).IsModified = true;
                    _taskDB.Entry(user).Property(e => e.RDepartment).IsModified = true;

                    await _taskDB.SaveChangesAsync();

                    return(true);
                }
                return(false);
            }
            catch
            {
                return(false);
            }
        }
예제 #2
0
        public async Task <bool> UpdateDepartment(Guid?id, Department departmentToUpdate)
        {
            try
            {
                var dept = await _taskDB.Department.Where(e => e.RowId == id).FirstOrDefaultAsync();

                if (dept != null)
                {
                    dept.Name        = departmentToUpdate.Name;
                    dept.Description = departmentToUpdate.Description;
                    dept.Address     = departmentToUpdate.Address;

                    _taskDB.Attach(dept);
                    _taskDB.Entry(dept).Property(e => e.Name).IsModified        = true;
                    _taskDB.Entry(dept).Property(e => e.Description).IsModified = true;
                    _taskDB.Entry(dept).Property(e => e.Address).IsModified     = true;

                    await _taskDB.SaveChangesAsync();

                    return(true);
                }
                return(false);
            }
            catch
            {
                return(false);
            }
        }