Ejemplo n.º 1
0
        public void UpdateAll(List <DepartmentFetched> departmentsFetched)
        {
            var departments = _repository.GetAll();

            // Delete should be cascade if it's necessary
            // foreach (var department in departments)
            // {
            //     if (!departmentsFetched.Select(v => v.Id).Contains(department.Code))
            //         _repository.Delete(department);
            // }
            foreach (var departmentFetched in departmentsFetched)
            {
                var foundDepartment = departments.SingleOrDefault(v => v.Code == departmentFetched.Id);
                if (foundDepartment == null)
                {
                    _repository.Add(departmentFetched.ToDepartment());
                }
                else
                {
                    var wasChanged = false;
                    var name       = departmentFetched.Name.Trim();
                    if (foundDepartment.Name != name)
                    {
                        foundDepartment.Name = name;
                        wasChanged           = true;
                    }
                    var shortName = departmentFetched.Reduction.Trim();
                    if (foundDepartment.ShortName != shortName)
                    {
                        foundDepartment.ShortName = shortName;
                        wasChanged = true;
                    }
                    if (foundDepartment.IsActive != departmentFetched.Enable)
                    {
                        foundDepartment.IsActive = departmentFetched.Enable;
                        wasChanged = true;
                    }
                    if (wasChanged)
                    {
                        _repository.Update(foundDepartment);
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public async Task <IEnumerable <Department> > GetDepartments()
 {
     //  DataGenerator dg = new DataGenerator(_context);
     //await  dg.FakeDpt();
     return(await _context.GetAll());
 }
 public IActionResult GetDepartments()
 {
     return(Ok(_deptRepo.GetAll()));
 }
Ejemplo n.º 4
0
 public IEnumerable <Department> GetAll()
 {
     return(_repository.GetAll());
 }