public virtual ActionResult Index()
        {
            ProviderSearchModel oModel = new ProviderSearchModel();
            int oTotalRows;

            oModel.Customers = DocumentManagement.Customer.Controller.Customer.CustomerSearch(null, 0, 20, out oTotalRows);
            //oModel.Forms = DocumentManagement.Customer.Controller.Customer.FormSearch(null, 0, 20, out oTotalRows);
            return(View(oModel));
        }
        public ProviderSearchModel ProviderSearch
            (string ProviderSearchVal, string SearchParam, int PageNumber, int RowCount, string CustomerPublicId, string FormPublicId, string Unique)
        {
            ProviderSearchModel oReturn = new ProviderSearchModel();

            int oTotalRows;
            List <DocumentManagement.Provider.Models.Provider.ProviderModel> oProviderlst = DocumentManagement.Provider.Controller.Provider.ProviderSearch
                                                                                                (SearchParam, CustomerPublicId, FormPublicId, PageNumber, RowCount, out oTotalRows, Convert.ToBoolean(Unique));

            oReturn.TotalRows = oTotalRows;

            oReturn.RelatedProvider = new List <ProviderItemSearchModel>();
            oProviderlst.All(prv =>
            {
                #region Lead
                prv.RelatedProviderCustomerInfo.All(y =>
                {
                    if (y.ProviderInfoType.ItemId == 403)
                    {
                        y.Value = DocumentManagement.Models.General.InternalSettings.Instance[DocumentManagement.Models.General.Constants.C_Settings_Path_SalesForce].Value + y.Value;
                    }
                    return(true);
                });
                #endregion
                oReturn.RelatedProvider.Add(new ProviderItemSearchModel()
                {
                    RelatedProvider    = prv,
                    codSalesforce      = prv.RelatedProviderCustomerInfo.Where(x => x.ProviderInfoType.ItemId == 403).Select(x => x.Value).FirstOrDefault() == null ? string.Empty : prv.RelatedProviderCustomerInfo.Where(x => x.ProviderInfoType.ItemId == 403).Select(x => x.Value).FirstOrDefault(),
                    checkDigit         = prv.RelatedProviderCustomerInfo.Where(x => x.ProviderInfoType.ItemId == 378).Select(x => x.Value).FirstOrDefault() == null ? string.Empty : prv.RelatedProviderCustomerInfo.Where(x => x.ProviderInfoType.ItemId == 378).Select(x => x.Value).FirstOrDefault(),
                    lastModify         = prv.LogCreateDate,
                    LastModifyUser     = prv.LogUser,
                    CustomerInfoTypeId = prv.RelatedProviderCustomerInfo.Where(x => x.ProviderInfoType.ItemId == 403).Select(x => x.ProviderInfoId).FirstOrDefault() == null ? 0 : prv.RelatedProviderCustomerInfo.Where(x => x.ProviderInfoType.ItemId == 403).Select(x => x.ProviderInfoId).FirstOrDefault(),
                    checkDigitInfoId   = prv.RelatedProviderCustomerInfo.Where(x => x.ProviderInfoType.ItemId == 378).Select(x => x.ProviderInfoId).FirstOrDefault() == null ? 0 : prv.RelatedProviderCustomerInfo.Where(x => x.ProviderInfoType.ItemId == 378).Select(x => x.ProviderInfoId).FirstOrDefault(),
                    oTotalRows         = oTotalRows
                });

                return(true);
            });

            return(oReturn);
        }
        public virtual ActionResult DownloadFile()
        {
            ProviderSearchModel oReturn = new ProviderSearchModel();

            int oTotalRows;
            List <DocumentManagement.Provider.Models.Provider.ProviderModel> oProviderlst = DocumentManagement.Provider.Controller.Provider.ProviderSearch
                                                                                                (Request["divGridProvider_txtSearch"] == "" ? null : Request["divGridProvider_txtSearch"]
                                                                                                , Request["CustomerName"] == "" ? null : Request["CustomerName"]
                                                                                                , Request["FormId"] == "" ? null : Request["FormId"]
                                                                                                , 0, 65000, out oTotalRows,
                                                                                                Convert.ToBoolean(Request["chk_Unique"]));

            oReturn.RelatedProvider = new List <ProviderItemSearchModel>();
            oProviderlst.All(prv =>
            {
                oReturn.RelatedProvider.Add(new ProviderItemSearchModel()
                {
                    RelatedProvider = prv,
                });

                return(true);
            });
            string strSep = ";";


            StringBuilder data = new StringBuilder();

            foreach (var item in oProviderlst)
            {
                string Campana = "";

                ProviderInfoModel info = item.RelatedProviderCustomerInfo.Where(x => x.ProviderInfoType.ItemId == 403).Select(x => x).FirstOrDefault() == null ? null : item.RelatedProviderCustomerInfo.Where(x => x.ProviderInfoType.ItemId == 403).Select(x => x).FirstOrDefault();
                if (info != null && info.ProviderInfoType.ItemId == 403)
                {
                    Campana = info.Value;
                }
                else
                {
                    Campana = "N/A";
                }

                if (oProviderlst.IndexOf(item) == 0)
                {
                    data.AppendLine
                        ("\"" + "RAZON SOCIAL" + "\"" + strSep +
                        "\"" + "TIPO IDENTIFICACION" + "\"" + strSep +
                        "\"" + "NUMERO IDENTIFICACION" + "\"" + strSep +
                        "\"" + "EMAIL" + "\"" + strSep +
                        "\"" + "CAMPANA" + "\"" + strSep +
                        "\"" + "URL" + "\"" + strSep +
                        "\"" + "FECHA MODIFICACION" + "\"" + strSep +
                        "\"" + "USUARIO ULTIMA MODIFICACION" + "\"");

                    data.AppendLine
                        ("\"" + item.Name + "\"" + "" + strSep +
                        "\"" + item.IdentificationType.ItemName + "\"" + strSep +
                        "\"" + item.IdentificationNumber + "\"" + strSep +
                        "\"" + item.Email + "\"" + strSep +
                        "\"" + Campana + "\"" + strSep +
                        "\"" + Url.Action(MVC.ProviderForm.ActionNames.Index,
                                          MVC.ProviderForm.Name,
                                          new
                    {
                        ProviderPublicId = item.ProviderPublicId,
                        FormPublicId     = item.FormPublicId
                    }) + "\"" + strSep +
                        "\"" + item.LogCreateDate + "\"" + strSep +
                        "\"" + item.LogUser + "\"");
                }
                else
                {
                    data.AppendLine
                        ("\"" + item.Name + "\"" + "" + strSep +
                        "\"" + item.IdentificationType.ItemName + "\"" + strSep +
                        "\"" + item.IdentificationNumber + "\"" + strSep +
                        "\"" + item.Email + "\"" + strSep +
                        "\"" + Campana + "\"" + strSep +
                        "\"" + Url.Action(MVC.ProviderForm.ActionNames.Index,
                                          MVC.ProviderForm.Name,
                                          new
                    {
                        ProviderPublicId = item.ProviderPublicId,
                        FormPublicId     = item.FormPublicId
                    }) + "\"" + strSep +
                        "\"" + item.LogCreateDate + "\"" + strSep +
                        "\"" + item.LogUser + "\"");
                }
            }

            byte[] buffer = Encoding.ASCII.GetBytes(data.ToString().ToCharArray());

            return(File(buffer, "application/csv", "Proveedores_" + DateTime.Now.ToString("yyyyMMddHHmm") + ".csv"));
        }