Exemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,MaxBet,Skill,Name")] Croupiers croupiers)
        {
            if (id != croupiers.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(croupiers);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CroupiersExists(croupiers.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(croupiers));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("Id,MaxBet,Skill,Name")] Croupiers croupiers)
        {
            if (ModelState.IsValid)
            {
                _context.Add(croupiers);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(croupiers));
        }
Exemplo n.º 3
0
        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))
                        {
                            //перегляд усіх листів (в даному випадку категорій)
                            foreach (IXLWorksheet worksheet in workBook.Worksheets)
                            {
                                //worksheet.Name - назва категорії. Пробуємо знайти в БД, якщо відсутня, то створюємо нову
                                Config newcat;
                                var    c = (from cat in _context.Config
                                            where cat.Name.Contains(worksheet.Name)
                                            select cat).ToList();
                                if (c.Count > 0)
                                {
                                    newcat = c[0];
                                }
                                else
                                {
                                    newcat           = new Config();
                                    newcat.Name      = worksheet.Name;
                                    newcat.MinBet    = -1;
                                    newcat.RoundTime = -1;
                                    // newcat.Info = "from EXCEL";
                                    //додати в контекст
                                    _context.Config.Add(newcat);
                                }
                                //перегляд усіх рядкі в
                                foreach (IXLRow row in worksheet.RowsUsed().Skip(1))
                                {
                                    try
                                    {
                                        Game book = new Game();
                                        row.Cell(1).TryGetValue(out DateTime value);
                                        book.Date = value;
                                        row.Cell(2).TryGetValue(out int value1);
                                        book.CroupierId = value1;
                                        row.Cell(3).TryGetValue(out int value2);
                                        book.TableId = value2;

                                        book.Config = newcat;
                                        _context.Game.Add(book);
                                        //у разі наявності автора знайти його, у разі відсутності - додати
                                        if (row.Cell(2).Value.ToString().Length > 0)
                                        {
                                            Croupiers author;

                                            var a = (from aut in _context.Croupiers
                                                     where aut.Name.Contains(row.Cell(2).Value.ToString())
                                                     select aut).ToList();
                                            if (a.Count > 0)
                                            {
                                                author = a[0];
                                            }
                                            else
                                            {
                                                author        = new Croupiers();
                                                author.Name   = row.Cell(2).Value.ToString();
                                                author.MaxBet = -1;
                                                author.Skill  = -1;
                                                //додати в контекст
                                                _context.Add(author);
                                            }
                                        }
                                        if (row.Cell(3).Value.ToString().Length > 0)
                                        {
                                            Tables author;

                                            var a = (from aut in _context.Tables
                                                     where aut.Id.ToString().Contains(row.Cell(3).Value.ToString())
                                                     select aut).ToList();
                                            if (a.Count > 0)
                                            {
                                                author = a[0];
                                            }
                                            else
                                            {
                                                author = new Tables();
                                                row.Cell(3).TryGetValue(out int value3);
                                                author.Id       = value3;
                                                author.Capacity = -1;
                                                author.MaxBet   = -1;
                                                //додати в контекст
                                                _context.Add(author);
                                            }
                                        }
                                    }
                                    catch (Exception e)
                                    {
                                        //logging самостійно :)
                                    }
                                }
                            }
                        }
                    }
                }

                await _context.SaveChangesAsync();
            }
            return(RedirectToAction(nameof(Index)));
        }