public ActionResult BookGroupTrip(GroupTripModel groupTripModel)
        {
            if (!SessionManager.userIsLoggedIn())
            {
                return(new HttpStatusCodeResult(403));
            }

            if (ModelState.IsValid)
            {
                Route    route    = BL.MainClass.Instance.getRoutes().Find(v => v.id == groupTripModel.routeId);
                TripType triptype = BL.MainClass.Instance.getTripTypes().Find(v => v.id == groupTripModel.tripTypeId);
                Ship     ship     = BL.MainClass.Instance.getShips().Find(v => v.id == groupTripModel.shipTypeId);

                // Select dummy price categories because of project finish time reasons
                PriceCategory children = MainClass.Instance.getPriceCategories().Find(v => v.name == "Children");
                if (children == null)
                {
                    BL.PersonCategory pc = new BL.PersonCategory("Children");
                    MainClass.Instance.addPersonCategory(pc);

                    MainClass.Instance.addPriceCategory(new BL.PriceCategory("Children", triptype, pc, 4, route));
                }

                PriceCategory adults = MainClass.Instance.getPriceCategories().Find(v => v.name == "Adults");
                if (adults == null)
                {
                    BL.PersonCategory pc = new BL.PersonCategory("Adults");
                    MainClass.Instance.addPersonCategory(pc);

                    MainClass.Instance.addPriceCategory(new BL.PriceCategory("Adults", triptype, pc, 7, route));
                }
                BL.GroupTrip groupTrip = new GroupTrip(route, groupTripModel.depatureTime, triptype, ship);

                groupTrip.setPersonsOnBoard(children, groupTripModel.children);
                groupTrip.setPersonsOnBoard(adults, groupTripModel.adults);

                if (MainClass.Instance.canOrderGroupTrip(groupTrip))
                {
                    groupTripModel.totalPrice       = groupTrip.getTotalPrice();
                    groupTripModel.ship             = ship;
                    groupTripModel.tripType         = triptype;
                    groupTripModel.route            = route;
                    groupTripModel.finalGroupTrip   = groupTrip;
                    groupTripModel.routeName        = route.getRouteString();
                    groupTripModel.adultPrice       = adults.price;
                    groupTripModel.childPrice       = children.price;
                    groupTripModel.driveTimeMinutes = (int)groupTrip.getTotalDriveTimeMinutes();
                    groupTripModel.returnTime       = groupTrip.returnTime;

                    System.Web.HttpContext.Current.Session["groupTrip"] = groupTripModel;
                    return(RedirectToAction("OrderGroupTrip", "Trip"));
                }
            }
            ViewBag.Status  = false;
            ViewBag.Message = "Group trip can not be ordered. Please make sure you enter the correct depature time " +
                              "and number of persons not bigger than the capacity according to the price category.";
            return(initialGroupTripView());
        }
Example #2
0
        public async Task <int> CreateAsync(GroupTripCreateInputModel inputModel, string userId)
        {
            var groupTrip = new GroupTrip
            {
                WaterPoolName         = inputModel.WaterPoolName,
                Description           = inputModel.Description,
                FreeSeats             = inputModel.FreeSeats,
                MeetingTime           = inputModel.MeetingTime,
                MeetingSpotLatitude   = inputModel.MeetingSpotLatitude,
                MeetingSpotLongtitude = inputModel.MeetingSpotLongtitude,
                FishingTime           = inputModel.FishingTime,
                FishingSpotLatitued   = inputModel.FishingSpotLatitude,
                FishingSpotLongtitude = inputModel.FishingSpotLongtitude,
                TargetFishSpeciesId   = inputModel.TargetFishSpeciesId,
                FishingMethod         = (FishingMethodEnum)inputModel.FishingMethodId,
                HostId = userId,
            };

            await this.groupTripsRepository.AddAsync(groupTrip);

            await this.groupTripsRepository.SaveChangesAsync();

            return(groupTrip.Id);
        }