Пример #1
0
        public async Task <IActionResult> CreateOptimalGroupAsync(OptimalGroupViewModel ogvm, int[] items)
        {
            List <Car> carsThisGroup = new List <Car>();

            foreach (int i in items)
            {
                carsThisGroup.Add(_carManager.Get(i));
            }


            Group group = new Group()
            {
                IdGroup   = 0,
                IdOwner   = _userRepository.Get(_userManager.GetUserId(HttpContext.User)),
                GroupName = "GroupFor" + _cargoManager.Get(ogvm.Cargo.Id_Cargo).CargoName,
            };

            _groupsRepository.Create(group);

            // await _groupsRepository.SaveChangesAsync();

            foreach (Car car in carsThisGroup)
            {
                car.IdGroup = group;
            }

            _groupsRepository.UpdateMany(carsThisGroup); // ошбика отслеживания Пользователя?!
            await _groupsRepository.SaveChangesAsync();

            return(RedirectToAction("Index", "Home"));
        }
Пример #2
0
        public IActionResult OptimalGroup(int idCargo)
        {
            var ogv = new OptimalGroupViewModel
            {
                CarsThisGroup = _groupRepository.CreateGroupForCargo(idCargo, _userManager.GetUserId(HttpContext.User)),
                Cargo         = _cargoRepository.Get(idCargo)
            };

            return(View(ogv));
        }