public async Task <IActionResult> Create([Bind("Id,Name,Pricefactor")] Carriagetype carriagetype)
        {
            if (ModelState.IsValid)
            {
                _context.Add(carriagetype);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(carriagetype));
        }
        public async Task <IActionResult> Create([Bind("Id,Name")] Country country)
        {
            if (ModelState.IsValid)
            {
                _context.Add(country);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(country));
        }
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,MiddleName,PassportSerial")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
        public async Task <IActionResult> Create([Bind("Id,Value")] Prefix prefix)
        {
            if (ModelState.IsValid)
            {
                _context.Add(prefix);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(prefix));
        }
        public async Task <IActionResult> Create([Bind("Id,PricePerKilometer")] Locomotive locomotive)
        {
            if (ModelState.IsValid)
            {
                _context.Add(locomotive);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(locomotive));
        }
        public async Task <IActionResult> Create([Bind("Id,LocomotiveId")] Trip trip)
        {
            if (ModelState.IsValid)
            {
                _context.Add(trip);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["LocomotiveId"] = new SelectList(_context.Locomotive, "Id", "Id", trip.LocomotiveId);
            return(View(trip));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Create([Bind("Id,Name,RegionId")] City city)
        {
            if (ModelState.IsValid)
            {
                _context.Add(city);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["RegionId"] = new SelectList(_context.Region, "Id", "Name", city.RegionId);
            return(View(city));
        }
Exemplo n.º 8
0
        public async Task <IActionResult> Create([Bind("Id,Name,CountryId")] Region region)
        {
            if (ModelState.IsValid)
            {
                _context.Add(region);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CountryId"] = new SelectList(_context.Country, "Id", "Name", region.CountryId);
            return(View(region));
        }
Exemplo n.º 9
0
        public async Task <IActionResult> Create([Bind("Id,CarriageTypeId,Number,Seats")] Carriage carriage)
        {
            if (ModelState.IsValid)
            {
                _context.Add(carriage);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CarriageTypeId"] = new SelectList(_context.Carriagetype, "Id", "Name", carriage.CarriageTypeId);
            return(View(carriage));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,PrefixId,CityId")] Station station)
        {
            if (ModelState.IsValid)
            {
                _context.Add(station);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CityId"]   = new SelectList(_context.City, "Id", "Name", station.CityId);
            ViewData["PrefixId"] = new SelectList(_context.Prefix, "Id", "Value", station.PrefixId);
            return(View(station));
        }
Exemplo n.º 11
0
        public async Task <IActionResult> Create([Bind("Id,ArriveTime,PointId,TripId")] Arrivaltime arrivaltime)
        {
            if (ModelState.IsValid)
            {
                _context.Add(arrivaltime);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PointId"] = new SelectList(_context.Point, "Id", "Id", arrivaltime.PointId);
            ViewData["TripId"]  = new SelectList(_context.Trip, "Id", "Id", arrivaltime.TripId);
            return(View(arrivaltime));
        }
        public async Task <IActionResult> Create([Bind("Id,StayTime,TripDistance,RouteId,StationId")] Point point)
        {
            if (ModelState.IsValid)
            {
                _context.Add(point);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["RouteId"]   = new SelectList(_context.Route, "Id", "Name", point.RouteId);
            ViewData["StationId"] = new SelectList(_context.Station, "Id", "Name", point.StationId);
            return(View(point));
        }
        public async Task <IActionResult> Create([Bind("Id,CarriageId,LocomotiveId,FreeSeats")] CarriageHasLocomotive carriageHasLocomotive)
        {
            if (ModelState.IsValid)
            {
                _context.Add(carriageHasLocomotive);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CarriageId"]   = new SelectList(_context.Carriage, "Id", "Id", carriageHasLocomotive.CarriageId);
            ViewData["LocomotiveId"] = new SelectList(_context.Locomotive, "Id", "Id", carriageHasLocomotive.LocomotiveId);
            return(View(carriageHasLocomotive));
        }
        public async Task <IActionResult> Create([Bind("Id,Price,CarriageNumber,Depart,Arrive,UserId")] Ticket ticket)
        {
            if (ModelState.IsValid)
            {
                _context.Add(ticket);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Arrive"] = new SelectList(_context.Arrivaltime, "Id", "Id", ticket.Arrive);
            ViewData["Depart"] = new SelectList(_context.Arrivaltime, "Id", "Id", ticket.Depart);
            ViewData["UserId"] = new SelectList(_context.User, "Id", "FirstName", ticket.UserId);
            return(View(ticket));
        }
        public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    var railwayUser = new User();
                    railwayUser.Id             = user.Id;
                    railwayUser.FirstName      = model.FirstName;
                    railwayUser.LastName       = model.LastName;
                    railwayUser.MiddleName     = model.MiddleName;
                    railwayUser.PassportSerial = model.PassportSerial;

                    _context.Add(railwayUser);
                    await _context.SaveChangesAsync();

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme);
                    await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl);

                    await _signInManager.SignInAsync(user, isPersistent : false);

                    _logger.LogInformation("User created a new account with password.");
                    return(RedirectToLocal(returnUrl));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public async Task <IActionResult> Ticket(int?tripID, int?fromID, int?toID, int?carriage)
        {
            if (tripID == null || fromID == null || toID == null || carriage == null)
            {
                return(NotFound());
            }

            var from = _context.Arrivaltime
                       .Include(ar => ar.Point.Station)
                       .FirstOrDefault(ar => ar.TripId == tripID && ar.Id == fromID);
            var to = _context.Arrivaltime
                     .Include(ar => ar.Point.Station)
                     .FirstOrDefault(ar => ar.TripId == tripID && ar.Id == toID);

            if (from == null || to == null)
            {
                return(NotFound());
            }

            if (from.Point.TripDistance > to.Point.TripDistance)
            {
                return(NotFound());
            }

            var carriageHasLocomotive = _context.CarriageHasLocomotive
                                        .Include(cl => cl.Carriage.CarriageType)
                                        .First(cl => cl.Id == carriage);

            if (carriageHasLocomotive == null)
            {
                return(NotFound());
            }

            var destination = to.Point.TripDistance - from.Point.TripDistance;

            var res = new TicketViewModel();

            res.carriage = carriageHasLocomotive.Carriage.Number.ToString();

            res.fromStation = from.Point.Station.Name;
            res.fromDate    = from.ArriveTime;
            res.toStation   = to.Point.Station.Name;
            res.toDate      = to.ArriveTime;

            var user = await _manager.GetUserAsync(HttpContext.User);

            var mainUser = _context.User.FirstOrDefault(u => u.Id == user.Id);

            res.fio           = mainUser.LastName + ' ' + mainUser.FirstName + ' ' + mainUser.MiddleName;
            res.passportSeria = mainUser.PassportSerial;

            res.price = destination * carriageHasLocomotive.Carriage.CarriageType.Pricefactor;

            if (--carriageHasLocomotive.FreeSeats > 0)
            {
                var ticket = new Ticket();
                ticket.Price            = res.price;
                ticket.DepartNavigation = from;
                ticket.ArriveNavigation = to;
                ticket.User             = mainUser;
                ticket.CarriageNumber   = Int32.Parse(res.carriage);


                _context.Add(ticket);
                _context.SaveChanges();
                return(View(res));
            }
            else
            {
                return(BadRequest());
            }
        }