public IActionResult Edit(int tankId, int distributorId, TankDistributor tankDistributor)
        {
            if (tankId != tankDistributor.TankId || distributorId != tankDistributor.DistributorId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _tankDistributorService.Edit(tankDistributor);
                    TempData["Info"] = "Dane połącznenie Zbiornika z Dystrybutorem zostało zaktualizowane";
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!_tankDistributorService.TankDistributorExists(tankId, distributorId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        TempData["Warning"] = "Wystąpił błąd podczas edycji połączenia Zbiorni-Dystrybutor";
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(tankDistributor));
        }
        public void Create(DistributorCreate distributorCreate)
        {
            try
            {
                Distributor distributorToAdd = new Distributor
                {
                    IsLocked = false,
                    Counter  = 0,
                    //TankDistributors = new List<TankDistributor>()
                };

                _context.Add(distributorToAdd);
                _context.SaveChanges();

                //if (distributorCreate.TankIds == null) distributorCreate.TankIds = new List<int>();

                foreach (int tankId in distributorCreate.TankIds)
                {
                    TankDistributor td = _tankDistributorService.Create(tankId, distributorToAdd.DistributorId);
                    distributorToAdd.TankDistributors.Add(td);
                    _tankService.GetById(tankId).TankDistributors.Add(td);
                }

                _context.SaveChanges();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
        }
 public IActionResult Create(TankDistributor tankDistributor)
 {
     if (ModelState.IsValid)
     {
         _tankDistributorService.Create(tankDistributor.TankId, tankDistributor.DistributorId);
         TempData["Info"] = "Połączenie Zbiornik-Dystrybutor zostało dodane";
         return(RedirectToAction(nameof(Index)));
     }
     return(View(tankDistributor));
 }
示例#4
0
 public void Edit(TankDistributor tankdistributor)
 {
     try
     {
         _context.Update(tankdistributor);
         _context.SaveChanges();
     }
     catch (Exception ex)
     {
         throw new Exception(ex.ToString());
     }
 }
        // GET: TankDistributor/Edit/5
        public IActionResult Edit(int tankId, int distributorId)
        {
            var tank = _tankDistributorService.GetById(tankId, distributorId);

            if (tank == null)
            {
                return(NotFound());
            }
            TankDistributor model = new TankDistributor
            {
                TankId        = tankId,
                DistributorId = distributorId,
                Tank          = _tankService.GetById(tankId),
                Distributor   = _distributorService.GetById(distributorId)
            };

            return(View(model));
        }
示例#6
0
        public TankDistributor Create(int tankId, int distributorId)
        {
            try
            {
                TankDistributor td = new TankDistributor()
                {
                    TankId        = tankId,
                    DistributorId = distributorId
                };
                _context.Add(td);
                _context.SaveChanges();

                return(td);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
        }