public HttpResponse Add(AddTripViewModel input)
        {
            if (!this.IsUserLoggedIn())
            {
                return(this.Redirect("/Users/Login"));
            }

            tripsService.Add(input);

            return(this.Redirect("/Trips/All"));
        }
Exemplo n.º 2
0
        public HttpResponse Add(TripsInputModel model)
        {
            if (!User.IsAuthenticated)
            {
                //return Redirect("/Users/Login");

                return(Error($"401 Unauthorized")); // This way is more ser-friendly
            }

            bool isParsed = DateTime.TryParseExact(model.DepartureTime, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out _);
            var  userId   = User.Id;

            if (string.IsNullOrWhiteSpace(model.StartPoint))
            {
                //return Redirect("/Trips/Add");
                return(Error("Start point is required")); // This way is more ser-friendly
            }

            if (string.IsNullOrWhiteSpace(model.EndPoint))
            {
                //return Redirect("/Trips/Add");
                return(Error("End point is required"));
            }

            if (2 > model.Seats || model.Seats > 6)
            {
                //return Redirect("/Trips/Add");
                return(Error("Seat should be between 2 and 6"));
            }

            if (string.IsNullOrWhiteSpace(model.Description) || model.Description.Length > 80)
            {
                //return Redirect("/Trips/Add");
                return(Error("Description is required and has max length of 80"));
            }

            if (!isParsed)
            {
                //return Redirect("/Trips/Add");
                return(Error("Invalid Departure time. Please use this format (dd.MM.yyyy HH: mm)"));
            }

            tripsService.Add(model, userId);

            return(Redirect("/"));
        }
Exemplo n.º 3
0
        public HttpResponse Add(TripsInputModel model)
        {
            if (!IsUserSignIn())
            {
                return(Redirect("/"));
            }

            bool isParsed = DateTime.TryParseExact(model.DepartureTime, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out _);
            var  userId   = GetUserId();

            if (string.IsNullOrWhiteSpace(model.StartPoint))
            {
                return(Error("Start point is required"));
            }

            if (string.IsNullOrWhiteSpace(model.EndPoint))
            {
                return(Error("End point is required"));
            }

            if (2 > model.Seats || model.Seats > 6)
            {
                return(Error("Seat should be between 2 and 6"));
            }

            if (string.IsNullOrWhiteSpace(model.Description) || model.Description.Length > 80)
            {
                return(Error("Description is required and has max length of 80"));
            }

            if (!isParsed)
            {
                return(Error("Invalid Departure time. Please use this format (dd.MM.yyyy HH: mm)"));
            }

            tripsService.Add(model, userId);

            return(Redirect("/Trips/All"));
        }
Exemplo n.º 4
0
        public HttpResponse Add(TripAddInputModel inputModel, User user)
        {
            if (!this.IsUserLoggedIn())
            {
                return(this.Redirect($"/Users/Login"));
            }

            if (inputModel.Seats < SeatsMinLength || inputModel.Seats > SeatsMaxLength)
            {
                return(this.View($"/Trips/Add"));
            }

            if (inputModel.Description.Length > DescriptionMaxLength)
            {
                return(this.View($"/Trips/Add"));
            }



            tripService.Add(inputModel, this.User);

            return(this.Redirect($"/Trips/All"));
        }