Пример #1
0
        /// <summary>
        /// Valida que un segment by Agency cumpla con los filtros actuales
        /// </summary>
        /// <param name="segmentByAgecy">Objeto a validar</param>
        /// <returns>True. Si cumple | False. No cumple</returns>
        /// <history>
        /// [emoguel] created 31/05/2016
        /// </history>
        private bool ValidateFilter(SegmentByAgency segmentByAgecy)
        {
            if (_nStatus != -1)//Filtro por estatus
            {
                if (segmentByAgecy.seA != Convert.ToBoolean(_nStatus))
                {
                    return(false);
                }
            }

            if (!string.IsNullOrWhiteSpace(_segmentByAgencyFilter.seID))//Filtro por ID
            {
                if (segmentByAgecy.seID != _segmentByAgencyFilter.seID)
                {
                    return(false);
                }
            }

            if (!string.IsNullOrWhiteSpace(_segmentByAgencyFilter.seN))//Filtro por descripcion
            {
                if (!segmentByAgecy.seN.Contains(_segmentByAgencyFilter.seN, StringComparison.OrdinalIgnoreCase))
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #2
0
        /// <summary>
        /// Abre la ventana detalle en modo "detalle" o "edición" dependiendo de sus permisos
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <history>
        /// [emoguel] created 31/05/2016
        /// </history>
        private void Cell_DoubleClick(object sender, RoutedEventArgs e)
        {
            SegmentByAgency          segmentByAgency    = (SegmentByAgency)dgrSegments.SelectedItem;
            frmSegmentByAgencyDetail frmSegmentByAgency = new frmSegmentByAgencyDetail();

            frmSegmentByAgency.Owner              = this;
            frmSegmentByAgency.enumMode           = (_blnEdit) ? EnumMode.Edit : EnumMode.Add;
            frmSegmentByAgency.oldSegmentByAgency = segmentByAgency;
            if (frmSegmentByAgency.ShowDialog() == true)
            {
                int nIndex = 0;
                List <SegmentByAgency> lstSegmentsByAgency = (List <SegmentByAgency>)dgrSegments.ItemsSource;
                if (ValidateFilter(frmSegmentByAgency.segmentByAgency))                               //Verificamos que cumpla con los filtros
                {
                    ObjectHelper.CopyProperties(segmentByAgency, frmSegmentByAgency.segmentByAgency); //Actualizamos los datos
                    lstSegmentsByAgency.Sort((x, y) => string.Compare(x.seN, y.seN));                 //Ordenamos la lista
                    nIndex = lstSegmentsByAgency.IndexOf(segmentByAgency);                            //Obtenemos la posición del registro
                }
                else
                {
                    lstSegmentsByAgency.Remove(segmentByAgency);                //Quitamos el registro
                }
                dgrSegments.Items.Refresh();                                    //Actualizamos la vista
                GridHelper.SelectRow(dgrSegments, nIndex);                      //Seleccionamos el registro
                StatusBarReg.Content = lstSegmentsByAgency.Count + " Segments"; //Actualizamos el contador
            }
        }
Пример #3
0
        /// <summary>
        /// Devuelve la lista de SegmentByAgcy
        /// </summary>
        /// <param name="segmentByAgency">Objeto con filtros adicionales</param>
        /// <param name="nStatus">-1. Todos los registros | 0.Registros Inactivos | 1.Registros Activos</param>
        /// <returns></returns>
        /// <history>
        /// [emoguel] created 11/03/2016
        /// [emoguel] modified 17/03/2016--->Se agregó la validacion null del objeto y se cambió el filtro por descripcion a "contains"
        /// [emoguel] modified 31/05/2016--->Se volvió async
        /// </history>
        public async static Task <List <SegmentByAgency> > GetSegMentsByAgency(SegmentByAgency segmentByAgency = null, int nStatus = -1)
        {
            List <SegmentByAgency> lstSegmentsByAgency = new List <SegmentByAgency>();
            await Task.Run(() =>
            {
                using (var dbContext = new IMEntities(ConnectionHelper.ConnectionString()))
                {
                    var query = from sba in dbContext.SegmentsByAgencies
                                select sba;

                    if (nStatus != -1)//Filtro por Estatus
                    {
                        bool blnStatus = Convert.ToBoolean(nStatus);
                        query          = query.Where(sba => sba.seA == blnStatus);
                    }

                    if (segmentByAgency != null)                              //Valida si se tiene un objeto
                    {
                        if (!string.IsNullOrWhiteSpace(segmentByAgency.seID)) //Filtro por ID
                        {
                            query = query.Where(sba => sba.seID == segmentByAgency.seID);
                        }

                        if (!string.IsNullOrWhiteSpace(segmentByAgency.seN))//Fitro por nombre(Descripcion)
                        {
                            query = query.Where(sba => sba.seN.Contains(segmentByAgency.seN));
                        }
                    }

                    lstSegmentsByAgency = query.OrderBy(sba => sba.seN).ToList();
                }
            });

            return(lstSegmentsByAgency);
        }
Пример #4
0
        /// <summary>
        /// Carga el grid de segmentByAgency
        /// </summary>
        /// <param name="segmentByAgency">objeto a seleccionar</param>
        /// <history>
        /// [emoguel] created 31/05/2016
        /// </history>
        private async void LoadSegmentsByAgency(SegmentByAgency segmentByAgency = null)
        {
            try
            {
                status.Visibility = Visibility.Visible;
                int nIndex = 0;
                List <SegmentByAgency> lstSegmentsByAgency = await BRSegmentsByAgency.GetSegMentsByAgency(_segmentByAgencyFilter, _nStatus);

                dgrSegments.ItemsSource = lstSegmentsByAgency;
                if (lstSegmentsByAgency.Count > 0 && segmentByAgency != null)
                {
                    segmentByAgency = lstSegmentsByAgency.Where(sg => sg.seID == segmentByAgency.seID).FirstOrDefault();
                    nIndex          = lstSegmentsByAgency.IndexOf(segmentByAgency);
                }
                GridHelper.SelectRow(dgrSegments, nIndex);
                StatusBarReg.Content = lstSegmentsByAgency.Count + " Segments.";
                status.Visibility    = Visibility.Collapsed;
            }
            catch (Exception ex)
            {
                UIHelper.ShowMessage(ex);
            }
        }
Пример #5
0
        /// <summary>
        /// Recarga los datos del grid
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <history>
        /// [emoguel] created 31/05/2016
        /// </history>
        private void btnRef_Click(object sender, RoutedEventArgs e)
        {
            SegmentByAgency segmentbyAgency = (SegmentByAgency)dgrSegments.SelectedItem;

            LoadSegmentsByAgency(segmentbyAgency);
        }
Пример #6
0
        /// <summary>
        /// Guarda un registro en el catalogo Segments By Agency
        /// Desasigna|Asigna Agencias a un segment
        /// </summary>
        /// <param name="segmentByAgency">OBjeto a guardar</param>
        /// <param name="lstAdd">Lista a asignar</param>
        /// <param name="lstDel">Lista a desasignar</param>
        /// <param name="blnUpdate">True. Actualiza | False. Inserta</param>
        /// <returns>-1. Existe un registro con el mismo ID | 0. No se guardó | 1. Se guardó</returns>
        /// <history>
        /// [emoguel] created 31/05/2016
        /// </history>
        public async static Task <int> SaveSegmentByAgency(SegmentByAgency segmentByAgency, List <Agency> lstAdd, List <Agency> lstDel, bool blnUpdate)
        {
            int nRes = await Task.Run(() => {
                using (var dbContext = new IMEntities(ConnectionHelper.ConnectionString()))
                {
                    using (var transacction = dbContext.Database.BeginTransaction(System.Data.IsolationLevel.Serializable))
                    {
                        try
                        {
                            #region Update
                            if (blnUpdate)
                            {
                                dbContext.Entry(segmentByAgency).State = System.Data.Entity.EntityState.Modified;
                            }
                            #endregion
                            #region Add
                            else
                            {
                                if (dbContext.SegmentsByAgencies.Where(se => se.seID == segmentByAgency.seID).FirstOrDefault() != null)//Existe un registro
                                {
                                    return(-1);
                                }
                                else//Agregar
                                {
                                    #region GetPosition
                                    var items = (from sa in dbContext.SegmentsByAgencies
                                                 select new Item
                                    {
                                        Id = sa.seO.ToString(),
                                        UserId = sa.seID,
                                        Name = sa.seN,
                                        By = "Agency"
                                    }).Union(from sl in dbContext.SegmentsByLeadSources
                                             select new Item
                                    {
                                        Id     = sl.soO.ToString(),
                                        UserId = sl.soID,
                                        Name   = sl.soN,
                                        By     = "Lead Source"
                                    }).ToList().OrderBy(it => int.Parse(it.Id)).ToList();
                                    var item            = items.LastOrDefault();
                                    segmentByAgency.seO = Convert.ToInt32(item.Id) + 1;
                                    #endregion
                                    dbContext.SegmentsByAgencies.Add(segmentByAgency);
                                }
                            }
                            #endregion

                            #region Agencies
                            //Asignar
                            dbContext.Agencies.AsEnumerable().Where(ag => lstAdd.Any(agg => agg.agID == ag.agID)).ToList().ForEach(ag =>
                            {
                                ag.agse = segmentByAgency.seID;
                            });

                            //Desasignar
                            dbContext.Agencies.AsEnumerable().Where(ag => lstDel.Any(agg => agg.agID == ag.agID)).ToList().ForEach(ag =>
                            {
                                ag.agse = null;
                            });
                            #endregion

                            int nSave = dbContext.SaveChanges();
                            transacction.Commit();
                            return(nSave);
                        }
                        catch
                        {
                            transacction.Rollback();
                            return(0);
                        }
                    }
                }
            });

            return(nRes);
        }