Beispiel #1
0
        public virtual JsonResult GetEntityList(string table, string field)
        {
            Table t = (Table)Enum.Parse(typeof(Table), table);
            Field f = (Field)Enum.Parse(typeof(Field), field);

            if (t == Table.Articles)
            {
                IArticleRepository repository = DependencyResolver.Current.GetService <IArticleRepository>();
                if (f == Field.Name)
                {
                    return(Json(repository.GetList().Select(x => new { x.Id, x.Name }), JsonRequestBehavior.AllowGet));
                }
                if (f == Field.Description)
                {
                    return(Json(repository.GetList().Select(x => new { x.Id, Name = x.Description }), JsonRequestBehavior.AllowGet));
                }
            }
            if (t == Table.Certificates)
            {
                ICertificatesRepository repository = DependencyResolver.Current.GetService <ICertificatesRepository>();
                if (f == Field.Name)
                {
                    return(Json(repository.GetList().Select(x => new { x.Id, x.Name }), JsonRequestBehavior.AllowGet));
                }
            }
            if (t == Table.Contacts)
            {
                IContactsRepository repository = DependencyResolver.Current.GetService <IContactsRepository>();
                if (f == Field.Name)
                {
                    return(Json(repository.GetList().Select(x => new { x.Id, x.Name }), JsonRequestBehavior.AllowGet));
                }
                if (f == Field.Description)
                {
                    return(Json(repository.GetList().Select(x => new { x.Id, Name = x.Description }), JsonRequestBehavior.AllowGet));
                }
            }
            if (t == Table.Images)
            {
                IImagesRepository repository = DependencyResolver.Current.GetService <IImagesRepository>();
                if (f == Field.Name)
                {
                    return(Json(repository.GetList().Select(x => new { x.Id, x.Name }), JsonRequestBehavior.AllowGet));
                }
            }
            if (t == Table.Languages)
            {
                ILanguagesRepository repository = DependencyResolver.Current.GetService <ILanguagesRepository>();
                if (f == Field.Name)
                {
                    return(Json(repository.GetList().Select(x => new { x.Id, x.Name }), JsonRequestBehavior.AllowGet));
                }
            }
            if (t == Table.PortfolioDetails)
            {
                IPortfolioDetailsRepository repository = DependencyResolver.Current.GetService <IPortfolioDetailsRepository>();
                if (f == Field.Name)
                {
                    return(Json(repository.GetList().Select(x => new { x.Id, x.Name }), JsonRequestBehavior.AllowGet));
                }
            }
            if (t == Table.Portfolios)
            {
                IPortfoliosRepository repository = DependencyResolver.Current.GetService <IPortfoliosRepository>();
                if (f == Field.Name)
                {
                    return(Json(repository.GetList().Select(x => new { x.Id, x.Name }), JsonRequestBehavior.AllowGet));
                }
                if (f == Field.Description)
                {
                    return(Json(repository.GetList().Select(x => new { x.Id, Name = x.Description }), JsonRequestBehavior.AllowGet));
                }
            }
            if (t == Table.ProductCategories)
            {
                IProductCategoriesRepository repository = DependencyResolver.Current.GetService <IProductCategoriesRepository>();
                if (f == Field.Name)
                {
                    return(Json(repository.GetList().Select(x => new { x.Id, x.Name }), JsonRequestBehavior.AllowGet));
                }
                if (f == Field.Description)
                {
                    return(Json(repository.GetList().Select(x => new { x.Id, Name = x.Description }), JsonRequestBehavior.AllowGet));
                }
            }
            if (t == Table.Products)
            {
                IProductsRepository repository = DependencyResolver.Current.GetService <IProductsRepository>();
                if (f == Field.Name)
                {
                    return(Json(repository.GetList().Select(x => new { x.Id, x.Name }), JsonRequestBehavior.AllowGet));
                }
                if (f == Field.Description)
                {
                    return(Json(repository.GetList().Select(x => new { x.Id, Name = x.Description }), JsonRequestBehavior.AllowGet));
                }
            }
            if (t == Table.Quotes)
            {
                IQuotesRepository repository = DependencyResolver.Current.GetService <IQuotesRepository>();
                if (f == Field.Description)
                {
                    return(Json(repository.GetList().Select(x => new { x.Id, Name = x.Description }), JsonRequestBehavior.AllowGet));
                }
            }
            if (t == Table.Sliders)
            {
                ISlidersRepository repository = DependencyResolver.Current.GetService <ISlidersRepository>();
                if (f == Field.Name)
                {
                    return(Json(repository.GetList().Select(x => new { x.Id, x.Name }), JsonRequestBehavior.AllowGet));
                }
            }

            return(Json("", JsonRequestBehavior.AllowGet));
        }
        //
        // GET: /Reports/QuoteCustomer/
        public ActionResult Index()
        {
            if (!CheckToken(Request.Headers))
            {
                return(RedirectToAction("Error"));
            }

            queryValues = Request.QueryString;

            int    page            = 0;
            int    start           = 0;
            int    limit           = 0;
            int    id              = Convert.ToInt32(queryValues["id"]);
            int    orden           = Convert.ToInt32(queryValues["orden"]);
            string filterDateField = queryValues["FilterDateField"];
            string strDateFrom     = queryValues["DateFrom"];
            string strDateTo       = queryValues["DateTo"];
            int    roleId          = Convert.ToInt32(queryValues["Role"]);

            string  strFilterBalance = queryValues["FilterBalance"];
            Decimal filterBalance    = String.IsNullOrEmpty(strFilterBalance) ? 0 : Convert.ToDecimal(strFilterBalance);

            string FilterShowWithInvoice = queryValues["FilterShowWithInvoice"];

            FilterShowWithInvoice = !String.IsNullOrEmpty(FilterShowWithInvoice) ? FilterShowWithInvoice : "All";


            #region Configuramos el orden de la consulta si se obtuvo como parametro
            string strOrder = !string.IsNullOrWhiteSpace(queryValues["sort"]) ? queryValues["sort"] : "";
            strOrder = strOrder.Replace('[', ' ');
            strOrder = strOrder.Replace(']', ' ');

            Sort sort;

            if (!string.IsNullOrWhiteSpace(strOrder))
            {
                sort = JsonConvert.DeserializeObject <Sort>(strOrder);
            }
            else
            {
                sort = new Sort();
            }
            #endregion

            #region Configuramos el filtro de la consulta si se obtuvo como parametro
            string strFilter = !string.IsNullOrWhiteSpace(queryValues["filter"]) ? queryValues["filter"] : "";
            strFilter = strFilter.Replace('[', ' ');
            strFilter = strFilter.Replace(']', ' ');

            Models.Filter filter;

            if (!string.IsNullOrWhiteSpace(strFilter))
            {
                filter = JsonConvert.DeserializeObject <Models.Filter>(strFilter);
            }
            else
            {
                filter = new Models.Filter();
            }
            #endregion Configuramos el filtro de la consulta si se obtuvo como parametro

            string query = !string.IsNullOrWhiteSpace(queryValues["query"]) ? queryValues["query"] : "";

            //queryValues = Request.QueryString;
            IList <QuoteHeader> lista;
            int    totalRecords = 0;
            string msgError     = "";

            lista = quoteRepository.GetList(query, filter, sort, page, start, limit, ref totalRecords, ref msgError);

            LocalReport lr = new LocalReport();

            try
            {
                lr.DataSources.Clear();
                lr.DataSources.Add(new ReportDataSource("dsQuotes", lista));

                if (roleId == -1)
                {
                    lr.ReportPath = "bin/Areas/Reports/ReportDesign/ReportQuotesGY.rdlc";
                }
                else
                {
                    lr.ReportPath = "bin/Areas/Reports/ReportDesign/ReportQuotes.rdlc";
                }

                string reportType = "EXCELOPENXML";
                string mimeType;
                string encoding;
                string fileNameExtension;

                string deviceInfo =
                    "<DeviceInfo>" +
                    "  <OutputFormat>" + id + "</OutputFormat>" +
                    "  <PageWidth>8.5in</PageWidth>" +
                    "  <PageHeight>11in</PageHeight>" +
                    "  <MarginTop>0.2in</MarginTop>" +
                    "  <MarginLeft>0.2in</MarginLeft>" +
                    "  <MarginRight>0.2in</MarginRight>" +
                    "  <MarginBottom>0.2in</MarginBottom>" +
                    "</DeviceInfo>";

                Warning[] warnings;
                string[]  streams;
                byte[]    bytes;

                bytes = lr.Render(
                    reportType,
                    deviceInfo,
                    out mimeType,
                    out encoding,
                    out fileNameExtension,
                    out streams,
                    out warnings);

                string     fileName = Utils.GetTempFileNameWithExt("xlsx");
                FileStream fs       = new FileStream(fileName, FileMode.OpenOrCreate);
                fs.Write(bytes, 0, bytes.Length);
                fs.Close();


                return(Content(Path.GetFileNameWithoutExtension(fileName)));
            }
            catch (Exception ex)
            {
                LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message);
                return(RedirectToAction("Error"));
            }
        }
        public object GetAll()
        {
            try
            {
                var queryValues = Request.RequestUri.ParseQueryString();

                int page  = Convert.ToInt32(queryValues["page"]);
                int start = Convert.ToInt32(queryValues["start"]);
                int limit = Convert.ToInt32(queryValues["limit"]);
                int id    = Convert.ToInt32(queryValues["id"]);
                int orden = Convert.ToInt32(queryValues["orden"]);

                string filterDateField = queryValues["FilterDateField"];
                string strDateFrom     = queryValues["DateFrom"];
                string strDateTo       = queryValues["DateTo"];
                int    roleId          = Convert.ToInt32(queryValues["Role"]);

                string  strFilterBalance = queryValues["FilterBalance"];
                Decimal filterBalance    = String.IsNullOrEmpty(strFilterBalance) ? 0 : Convert.ToDecimal(strFilterBalance);

                string FilterShowWithInvoice = queryValues["FilterShowWithInvoice"];

                FilterShowWithInvoice = !String.IsNullOrEmpty(FilterShowWithInvoice) ? FilterShowWithInvoice : "All";

                #region Configuramos el orden de la consulta si se obtuvo como parametro
                string strOrder = !string.IsNullOrWhiteSpace(queryValues["sort"]) ? queryValues["sort"] : "";
                strOrder = strOrder.Replace('[', ' ');
                strOrder = strOrder.Replace(']', ' ');

                Sort sort;

                if (!string.IsNullOrWhiteSpace(strOrder))
                {
                    sort = JsonConvert.DeserializeObject <Sort>(strOrder);
                }
                else
                {
                    sort = new Sort();
                }
                #endregion

                #region Configuramos el filtro de la consulta si se obtuvo como parametro
                string strFilter = !string.IsNullOrWhiteSpace(queryValues["filter"]) ? queryValues["filter"] : "";
                strFilter = strFilter.Replace('[', ' ');
                strFilter = strFilter.Replace(']', ' ');

                Filter filter;

                if (!string.IsNullOrWhiteSpace(strFilter))
                {
                    filter = JsonConvert.DeserializeObject <Filter>(strFilter);
                }
                else
                {
                    filter = new Filter();
                }
                #endregion Configuramos el filtro de la consulta si se obtuvo como parametro

                string query = !string.IsNullOrWhiteSpace(queryValues["query"]) ? queryValues["query"] : "";

                int totalRecords = 0;

                if (id == 0)
                {
                    object json;
                    string msgError = "";
                    var    lista    = repository.GetList(query, filter, sort, page, start, limit, ref totalRecords, ref msgError);

                    json = new
                    {
                        total   = totalRecords,
                        data    = lista,
                        success = true
                    };

                    return(json);
                }
                else
                {
                    string      msgError = "";
                    QuoteHeader estatus  = repository.Get(id, ref msgError);

                    object json = new
                    {
                        data    = estatus,
                        success = true,
                        message = msgError
                    };

                    return(json);
                }
            }
            catch (Exception ex)
            {
                LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message);

                object error = new { message = ex.Message };

                object json = new
                {
                    message = ex.Message,
                    success = false
                };

                return(json);
            }
        }
Beispiel #4
0
        public static List <Quote> GetQuotes()
        {
            IQuotesRepository repository = DependencyResolver.Current.GetService <IQuotesRepository>();

            return(repository.GetList().ToList());
        }