public void UpdateResponsibles(int activityId, int subActivityId, string newResponsiblesId)
        {
            using (IDataProvider provider = base.CreateDataProvider())
            using (IResponsiblesRepository repository = provider.CreateResponsiblesRepository())
            {
                ResponsiblesFilter responsiblesFilter = new ResponsiblesFilter()
                {
                    SubActivityId = subActivityId
                };

                List<Responsibles> responsibles = repository.GetResponsibles(responsiblesFilter);
                List<Responsibles> toDelete = new List<Responsibles>();
                List<Responsibles> toAdd = new List<Responsibles>();
                string[] newIds = newResponsiblesId.Split(',');
                HashSet<int> setNewIds = new HashSet<int>();
                HashSet<int> setOldIds = new HashSet<int>();

                foreach (var id in newIds)
                    setNewIds.Add(Convert.ToInt32(id));

                foreach (Responsibles responsible in responsibles)
                {
                    if (!setNewIds.Contains(responsible.Id))
                        toDelete.Add(responsible);
                    else
                        setOldIds.Add(responsible.Id);
                }

                foreach (var petianoId in setNewIds)
                {
                    if (!setOldIds.Contains(petianoId))
                        toAdd.Add(new Responsibles() { ActivityId = activityId, SubActivityId = subActivityId, PETianoId = petianoId });
                }

                foreach (var item in toDelete)
                    repository.Delete(item);

                repository.Create(toAdd);
            }
        }
        public ActionResult SubBoard(int activityId, int subActivityId = 0)
        {
            ActivityFilter activityFilter = new ActivityFilter()
            {
                Id = activityId
            };

            ResponsiblesFilter responsiblesFilter = new ResponsiblesFilter()
            {
                SubActivityId = subActivityId
            };

            SubActivityModel subActivityModel = new SubActivityModel()
            {
                Activity = _ActivityService.GetActivity(activityFilter),
                Responsibles = _ResponsiblesService.GetResponsibles(responsiblesFilter)
            };

            return View(subActivityModel);
        }
 public List<Responsibles> GetResponsibles(ResponsiblesFilter responsiblesFilter = null)
 {
     using (IBusinessProvider provider = base.CreateBusinessProvider())
     using (IResponsiblesBusinessProvider prov = provider.CreateResponsiblesBusinessProvider())
         return prov.GetResponsibles(responsiblesFilter);
 }
 public List<Responsibles> GetResponsibles(ResponsiblesFilter responsiblesFilter = null)
 {
     using (IDataProvider provider = base.CreateDataProvider())
     using (IResponsiblesRepository repository = provider.CreateResponsiblesRepository())
         return repository.GetResponsibles(responsiblesFilter);
 }
        public ActionResult ManageResponsibles(int activityId, int subActivityId)
        {
            ResponsiblesFilter responsiblesFilter = new ResponsiblesFilter()
            {
                SubActivityId = subActivityId
            };

            ResponsiblesModel responsibleModel = new ResponsiblesModel()
            {
                PETianos = _PETianoService.GetPETianos(),
                Responsibles = _ResponsiblesService.GetResponsibles(responsiblesFilter),
                ActivityId = activityId,
                SubActivityId = subActivityId
            };

            return View(responsibleModel);
        }