Пример #1
0
        public async Task UpdateTest()
        {
            using (var myContext = CreateMagasinDbContext())
            {
                var repo            = new PositionMagasinEFRepository(myContext);
                var positionMagasin = new PositionsMagasin
                {
                    ArticleId = 1,
                    EtagereId = 1,
                    Quantite  = 7
                };

                repo.Update(positionMagasin);
                await repo.Save();
            }
            using (var myContext = CreateMagasinDbContext())
            {
                var repo     = new PositionMagasinEFRepository(myContext);
                var elements = await repo.GetAll();

                elements.Should().HaveCount(3);
                elements.Any(e => e.Quantite == 7).Should().BeTrue();
                elements.Any(e => e.Quantite == 10).Should().BeFalse();
            }
        }
Пример #2
0
        public async Task <IActionResult> Edit(int EtagereId, int ArticleId, [Bind("ArticleId,EtagereId,Quantite")] PositionsMagasin positionsMagasin)
        {
            if (EtagereId != positionsMagasin.EtagereId || ArticleId != positionsMagasin.ArticleId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(positionsMagasin);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PositionsMagasinExists(positionsMagasin.EtagereId, positionsMagasin.ArticleId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ArticleId"] = new SelectList(_context.Articles, "Id", "Libelle", positionsMagasin.ArticleId);
            ViewData["EtagereId"] = new SelectList(_context.Etageres, "Id", "Id", positionsMagasin.EtagereId);
            return(View(positionsMagasin));
        }
Пример #3
0
        public async Task <IActionResult> Create([Bind("ArticleId,EtagereId,Quantite")] PositionsMagasin positionsMagasin)
        {
            if (ModelState.IsValid)
            {
                if (PositionsMagasinExists(positionsMagasin.EtagereId, positionsMagasin.ArticleId))
                {
                    _context.Update(positionsMagasin);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    _context.Add(positionsMagasin);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            ViewData["ArticleId"] = new SelectList(_context.Articles, "Id", "Libelle", positionsMagasin.ArticleId);
            ViewData["EtagereId"] = new SelectList(_context.Etageres, "Id", "Id", positionsMagasin.EtagereId);
            return(View(positionsMagasin));
        }
 public void Update(PositionsMagasin positionMagasin)
 {
     context.PositionsMagasin.Update(positionMagasin);
 }
 public void Remove(PositionsMagasin positionMagasin)
 {
     context.PositionsMagasin.Remove(positionMagasin);
 }
 public void Insert(PositionsMagasin positionMagasin)
 {
     context.PositionsMagasin.Add(positionMagasin);
 }
        public async Task <PositionsMagasin> FindById(int EtagereId, int ArticleId)
        {
            PositionsMagasin positionMagasin = await context.PositionsMagasin.FirstOrDefaultAsync(m => m.EtagereId == EtagereId && m.ArticleId == ArticleId);

            return(positionMagasin);
        }