示例#1
0
        public async Task <IActionResult> Create(RouteViewModel routeViewModel, IFormFile picture)
        {
            if (ModelState.IsValid)
            {
                if (picture != null)
                {
                    var fileName = Path.Combine(_env.WebRootPath, "uploads", Path.GetFileName(picture.FileName));
                    picture.CopyTo(new FileStream(fileName, FileMode.Create));
                }
                var route = new Route
                {
                    Price       = routeViewModel.Price,
                    Description = routeViewModel.Description,
                    CityFrom    = await _context.Cities.FindAsync(routeViewModel.CityFromId),
                    CityTo      = await _context.Cities.FindAsync(routeViewModel.CityToId),
                    Img         = picture.FileName
                };
                _context.Add(route);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Cities"] = (await _context.Cities.ToListAsync()).ConvertAll(c => new SelectListItem {
                Text = c.Title, Value = c.Id.ToString()
            });
            return(View(routeViewModel));
        }
示例#2
0
        public async Task <IActionResult> Create([Bind("Id,Name,SurName,Login,NumberPhone,Password,PasswordConfirm")] Driver driver)
        {
            if (ModelState.IsValid)
            {
                _context.Add(driver);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(driver));
        }
示例#3
0
        public async Task <IActionResult> Create([Bind("Id,Title")] City city)
        {
            if (ModelState.IsValid)
            {
                _context.Add(city);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(city));
        }
示例#4
0
        public async Task <IActionResult> Create([Bind("Id,Title,TypeCar,Number_of_the_car,Capacity,Comment")] Car car)
        {
            if (ModelState.IsValid)
            {
                _context.Add(car);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(car));
        }
示例#5
0
        public async Task <IActionResult> Create([Bind("Id,Amount,Name,Phone,FromPlaceInCity,ToPlaceInCity,DepartureDate,Comment,Route,RouteId")] Order order)
        {
            if (ModelState.IsValid)
            {
                _context.Add(order);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Routes"] = (await _context.Routes.Include(r => r.CityFrom).Include(r => r.CityTo).ToListAsync())
                                 .ConvertAll(c => new SelectListItem {
                Text = $"{c.CityFrom.Title} - {c.CityTo.Title}", Value = c.Id.ToString()
            });
            //ViewData["CustomerId"] = new SelectList(_context.Customers, "Id", "Id");
            return(View(order));
        }
示例#6
0
        public async Task <string> ShortOrder(ShortOrderViewModels shortOrderViewModels)
        {
            var newOrder = new Order
            {
                DepartureDate = DateTime.Now,
                Name          = shortOrderViewModels.Name,
                Phone         = shortOrderViewModels.Phone,
                Comment       = shortOrderViewModels.Comment,
                RouteId       = new Guid(shortOrderViewModels.RouteId),
                Route         = await _db.Routes.FirstOrDefaultAsync(r => r.Id.ToString() == shortOrderViewModels.RouteId)
            };

            _db.Orders.Add(newOrder);
            await _db.SaveChangesAsync();

            return("ok");
        }