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

            if (string.IsNullOrWhiteSpace(model.StartPoint) ||
                string.IsNullOrWhiteSpace(model.EndPoint) ||
                string.IsNullOrWhiteSpace(model.DepartureTime) ||
                string.IsNullOrWhiteSpace(model.Description) ||
                string.IsNullOrWhiteSpace(model.ImagePath) ||
                string.IsNullOrWhiteSpace(model.Seats) ||
                model.DepartureTime == null)
            {
                return(this.View());
            }

            if (int.Parse(model.Seats) < 2 || int.Parse(model.Seats) > 6)
            {
                return(this.View());
            }

            if (model.Description.Length > 80)
            {
                return(this.View());
            }

            this.tripService.AddTrip(model);

            return(this.Redirect("/Trips/All"));
        }
Пример #2
0
        public void AddTrip(TripAddBindingModel model)
        {
            var trip = new Trip
            {
                StartPoint    = model.StartPoint,
                EndPoint      = model.EndPoint,
                DepartureTime = DateTime.Parse(model.DepartureTime),
                Seats         = int.Parse(model.Seats),
                Description   = model.Description,
                ImagePath     = WebUtility.UrlDecode(model.ImagePath)
            };

            this.context.Add(trip);
            this.context.SaveChanges();
        }