Beispiel #1
0
        public async Task <IActionResult> Create([Bind("Excel,Reportes")] ProdEntry entry)
        {
            if (ModelState.IsValid)
            {
                if (entry?.Excel == null)
                {
                    return(View(nameof(Create)));
                }

                entry.AppUserId = _userManager.GetUserId(User);
                entry.IP        = Request.HttpContext.Connection.RemoteIpAddress.ToString();
                entry.FileName  = entry.Excel.FileName;
                entry.Date      = DateTime.Now;
                entry.Success   = false;
                _context.Add(entry);
                await _context.SaveChangesAsync()
                .ConfigureAwait(false);

                var result = string.Empty;

                //var debug = false;

                var toskip = new List <string> {
                    "Row", "Sheet", "Centre", "Rows", "Id", "Origin"
                };

                if (entry.Reportes != Tipo.Producción)
                {
                    toskip.Add("TipoProduccion");
                    toskip.Add("Dato");
                    toskip.Add("TipoItemProduccion");
                }

                if (entry.Reportes != Tipo.Semilla)
                {
                    toskip.Add("OrigenId");
                    toskip.Add("Origen");
                }

                Stream       stream  = entry.Excel.OpenReadStream();
                ExcelPackage package = new ExcelPackage(stream);

                await _import.Read <Planilla>(package, entry, toskip).ConfigureAwait(false);

                return(RedirectToAction(nameof(Index), new { id = entry.Id }));
            }
            var Filters = new Dictionary <string, List <string> >
            {
                ["Tipo"] = new List <string> {
                    "Semilla", "Cosecha", "Abastecimiento", "Producción"
                }
            };

            ViewData[nameof(Tipo)] = EViewData.Enum2Select <Tipo>(Filters, "Name");
            return(View(entry));
        }
Beispiel #2
0
        // GET: Entries
        public async Task <IActionResult> Index(int?id, int?pg, int?rpp, string srt,
                                                bool?asc, string[] val)
        {
            if (!pg.HasValue)
            {
                pg = 1;
            }
            if (!rpp.HasValue)
            {
                rpp = 20;
            }
            if (string.IsNullOrWhiteSpace(srt))
            {
                srt = "Date";
            }
            if (!asc.HasValue)
            {
                asc = false;
            }

            var pre  = _context.ProdEntry.Pre();
            var sort = _context.ProdEntry.FilterSort(srt);

            ViewData = _context.ProdEntry.ViewData(pre, pg, rpp, srt, asc, val);
            var Filters = ViewData["Filters"] as IDictionary <string, List <string> >;

            var applicationDbContext = asc.Value ?
                                       pre
                                       .OrderBy(x => sort.GetValue(x))
                                       .Skip((pg.Value - 1) * rpp.Value).Take(rpp.Value)
                                       .Include(e => e.AppUser) :
                                       pre
                                       .OrderByDescending(x => sort.GetValue(x))
                                       .Skip((pg.Value - 1) * rpp.Value).Take(rpp.Value)
                                       .Include(e => e.AppUser);

            ViewData["Processing"] = id;

            //if(Filters["Tipo"] == null || Filters["Tipo"].Count() == 0)
            //{
            Filters["Tipo"] = new List <string> {
                "Semilla", "Cosecha", "Abastecimiento", "Producción"
            };
            //}

            ViewData[nameof(Tipo)] = EViewData.Enum2Select <Tipo>(Filters, "Name");

            ViewData["Date"] = string.Format(CultureInfo.CurrentCulture, "'{0}'",
                                             string.Join("','", _context.ProdEntry.Select(v => v.Date.Date.ToString("yyyy-M-d", CultureInfo.CurrentCulture)).Distinct().ToList()));

            return(View(await applicationDbContext.ToListAsync().ConfigureAwait(false)));
        }