public async Task <IActionResult> Create([Bind("DiapasonId,Diapason1")] Diapason diapason)
        {
            if (ModelState.IsValid)
            {
                _context.Add(diapason);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(diapason));
        }
        public async Task <IActionResult> Create([Bind("StandartId,Standart1")] Standart standart)
        {
            if (ModelState.IsValid)
            {
                _context.Add(standart);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(standart));
        }
        public async Task <IActionResult> Create([Bind("RouterStandartId,RouterId,StandartId")] RouterStandart routerStandart)
        {
            if (ModelState.IsValid)
            {
                _context.Add(routerStandart);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["RouterId"]   = new SelectList(_context.Router, "RouterId", "Name", routerStandart.RouterId);
            ViewData["StandartId"] = new SelectList(_context.Standart, "StandartId", "Standart1", routerStandart.StandartId);
            return(View(routerStandart));
        }
Beispiel #4
0
        public async Task <IActionResult> Create([Bind("RouterId,Name,Year,PriceId,DiapasonId,SpeedId")] Router router)
        {
            if (ModelState.IsValid)
            {
                _context.Add(router);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DiapasonId"] = new SelectList(_context.Diapason, "DiapasonId", "Diapason1", router.DiapasonId);
            ViewData["PriceId"]    = new SelectList(_context.Price, "PriceId", "Price1", router.PriceId);
            ViewData["SpeedId"]    = new SelectList(_context.Speed, "SpeedId", "Speed1", router.SpeedId);
            return(View(router));
        }
        public async Task <IActionResult> Import(IFormFile fileExcel)
        {
            if (ModelState.IsValid)
            {
                if (fileExcel != null)
                {
                    using var stream = new FileStream(fileExcel.FileName, FileMode.Create);
                    await fileExcel.CopyToAsync(stream);

                    using XLWorkbook workBook = new XLWorkbook(stream, XLEventTracking.Disabled);
                    List <List <string> > Errors = new List <List <string> >();
                    foreach (IXLWorksheet worksheet in workBook.Worksheets)
                    {
                        Price price;
                        var   g = (from pr in _context.Price
                                   where pr.Price1 == worksheet.Name
                                   select pr).ToList();
                        if (g.Count > 0)
                        {
                            price = g[0];
                        }
                        else
                        {
                            price = new Price
                            {
                                Price1 = worksheet.Name
                            };
                            _context.Price.Add(price);
                        }
                        await _context.SaveChangesAsync();

                        foreach (IXLRow row in worksheet.RowsUsed().Skip(1))
                        {
                            Router router = new Router();
                            string name   = row.Cell(1).Value.ToString();
                            if (name.Length > 50 || name.Length < 3)
                            {
                                continue;
                            }
                            var f = (from rou in _context.Router where rou.Name == name select rou).ToList();
                            if (f.Count() > 0)
                            {
                                router = f[0];
                                await _context.SaveChangesAsync();
                            }
                            else
                            {
                                router.Name  = row.Cell(1).Value.ToString();
                                router.Price = price;
                                string name1 = row.Cell(2).Value.ToString();
                                if (name1.Length > 50 || name1.Length < 3)
                                {
                                    continue;
                                }
                                Speed speed;
                                var   a = (from pr in _context.Speed
                                           where pr.Speed1 == row.Cell(2).Value.ToString()
                                           select pr).ToList();
                                if (a.Count() > 0)
                                {
                                    speed        = a[0];
                                    router.Speed = speed;
                                }
                                else
                                {
                                    speed = new Speed
                                    {
                                        Speed1 = row.Cell(2).Value.ToString()
                                    };
                                    _context.Add(speed);
                                    router.Speed = speed;
                                }
                                string name2 = row.Cell(3).Value.ToString();

                                if (name2.Length > 50 || name2.Length < 2)
                                {
                                    continue;
                                }
                                Diapason diapason;
                                var      b = (from pr in _context.Diapason
                                              where pr.Diapason1 == row.Cell(3).Value.ToString()
                                              select pr).ToList();
                                if (b.Count() > 0)
                                {
                                    diapason        = b[0];
                                    router.Diapason = diapason;
                                }
                                else
                                {
                                    diapason = new Diapason
                                    {
                                        Diapason1 = row.Cell(3).Value.ToString()
                                    };
                                    _context.Add(diapason);
                                    router.Diapason = diapason;
                                }
                                _context.Router.Add(router);
                                await _context.SaveChangesAsync();
                            }
                        }
                    }
                    await _context.SaveChangesAsync();
                }
            }
            return(RedirectToAction("Index", "Routers"));
        }