public HttpResponse Add(TripsAddFormModel model)
        {
            var modelErrors = validator.ValidateTrip(model);

            if (modelErrors.Any())
            {
                return(Error(modelErrors));
            }

            var trip = new Trip()
            {
                StartPoint    = model.StartPoint,
                EndPoint      = model.EndPoint,
                DepartureTime = DateTime.ParseExact(model.DepartureTime, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture),
                Seats         = model.Seats,
                Description   = model.Description,
                ImagePath     = model.ImagePath,
            };

            data.Trips.Add(trip);
            data.SaveChanges();

            return(Redirect("/Trips/All"));
        }
        public string TryAddUserToTrip(string tripId, string userId)
        {
            var targetTrip = this.GetDetails(tripId);

            if (checkUserIsJoinedOnTrip(targetTrip, userId))
            {
                return("AlreadyIn");
            }
            if (this.GetTripFreePlaces(targetTrip) == 0)
            {
                return("Occupied");
            }
            var newUserTrip = new UserTrip
            {
                Trip   = targetTrip,
                UserId = userId
            };

            dbContext.UserTrips.Add(newUserTrip);
            dbContext.SaveChanges();
            return("Success");
        }
        public HttpResponse Register(UserRegisterModel model)
        {
            if (User.IsAuthenticated)
            {
                return(Redirect("/Trips/All"));
            }
            var modelErrors = this.validator.ValidateUser(model);

            if (this.data.Users.Any(u => u.Username == model.Username))
            {
                modelErrors.Add($"User with '{model.Username}' username already exists.");
            }

            if (this.data.Users.Any(u => u.Email == model.Email))
            {
                modelErrors.Add($"User with '{model.Email}' e-mail already exists.");
            }

            if (modelErrors.Any())
            {
                return(Error(modelErrors));
            }

            var user = new User
            {
                Username = model.Username,
                Password = this.passwordHasher.HashPassword(model.Password),
                Email    = model.Email,
            };

            data.Users.Add(user);

            data.SaveChanges();

            return(Redirect("/Users/Login"));
        }