private void AddReportFilters(IEnumerable <SubscriptionModel> subscriptions, Schedule model1, int UserId, int ID)
        {
            model1.UserId = UserId;
            _repo.Add(model1);
            foreach (var item in subscriptions)
            {
                SubscriptionModel subs = new SubscriptionModel(item.Email, item.Description, item.EmailComment, model1.ID, item.UserId);

                _repoSub.Add(subs);
                foreach (var filter in item.ReportFilters)
                {
                    ReportFilter reportfilter = new ReportFilter();
                    reportfilter.FilterID       = filter.FilterID;
                    reportfilter.ReportID       = filter.ReportID;
                    reportfilter.SubscriptionID = subs.Id;
                    reportfilter.Value          = filter.Value;
                    _repofilter.Add(reportfilter);
                }
            }
            _repo.Delete(ID);
        }
Exemplo n.º 2
0
        //crear el Subscription con los filters correspondientes
        private void FullAddModel(string email, string description, string emailComment, int scheduleId, int userId, int reportId, FormCollection model, int subId = 0)
        {
            SubscriptionModel submodel = null;

            if (subId == 0) //Si es Add
            {
                submodel = new SubscriptionModel(email, description, emailComment, scheduleId, userId);
                _repo.Add(submodel);
            }
            else
            {
                submodel = Edit(subId, email, description, emailComment, scheduleId);
            }
            bool entro = false;

            for (int i = 0; i < model.Count; i++)
            {
                string      key = model.GetKey(i).ToString();
                FilterModel f   = _repoFilter.FindAllBy(p => p.Name == key).FirstOrDefault();
                if (f != null && model.GetValue(key).AttemptedValue != string.Empty && model.GetValue(key).AttemptedValue != "-1")
                {
                    //Si subId == 0 adiciono Report Filter
                    if (subId == 0)
                    {
                        AddReportFilter(f.Id, reportId, submodel.Id, model.GetValue(key).AttemptedValue);
                    }
                    else
                    {
                        ReportFilter rfilter = _repoReportfilter.FindAllBy(p => p.SubscriptionID == subId && p.ReportID == reportId && p.FilterID == f.Id).FirstOrDefault();
                        if (rfilter != null)
                        {
                            rfilter.Value = model.GetValue(key).AttemptedValue;
                            _repoReportfilter.Edit(rfilter); //Si subId > 0 edit Report Filter
                        }
                        else
                        {//Si rfilter == null , significa que ese subscription no tenia ese filter y en la modificacion se creo nuevo,entonces se adiciona
                            AddReportFilter(f.Id, reportId, submodel.Id, model.GetValue(key).AttemptedValue);
                        }
                    }
                    entro = true;
                }
                else
                {//Si El subscription tenia un filter, pero en la modificacion se lo quitaron ,entonces se elimina
                    if (f != null && subId > 0)
                    {
                        ReportFilter rfilter = _repoReportfilter.FindAllBy(p => p.SubscriptionID == subId && p.ReportID == reportId && p.FilterID == f.Id).FirstOrDefault();
                        _repoReportfilter.DeleteReportFilter(rfilter);
                    }
                }
            }
            if (!entro && subId == 0)
            {//Si El report no tiene ningun filter se adiciona el filter ALL
                FilterModel  f            = _repoFilter.FindAllBy(p => p.Name == "ALL").FirstOrDefault();
                ReportFilter reportfilter = new ReportFilter()
                {
                    FilterID       = f.Id,
                    ReportID       = reportId,
                    SubscriptionID = submodel.Id,
                    Value          = "ALL"
                };
                _repoReportfilter.Add(reportfilter);
            }
        }