예제 #1
0
        public object Save(Entities.Booking Booking)
        {
            if (!ModelState.IsValid)
            {
                return(Error(ModelState));
            }

            if (Booking.Save())
            {
                return(Success(new
                {
                    Entity = Booking.Json()
                }));
            }

            return(Error());
        }
예제 #2
0
 public object Json()
 {
     return(new
     {
         Id,
         User = User?.Json(),
         Booking = Booking?.Json(),
         Title,
         TypeId,
         Type,
         StatusId,
         Status,
         GroupId,
         Group,
         DateCreated
     });
 }
예제 #3
0
 public object Json()
 {
     return(new
     {
         Id,
         Title,
         User = User?.Json(),
         Booking = Booking?.Json(),
         Amount,
         Credit,
         Debit,
         Reconciled,
         EcoCashReference,
         TypeId,
         Type,
         DateCreated,
         LastModified,
         Deleted,
         Balance
     });
 }
예제 #4
0
        public object AddBooking(BookingModel Model)
        {
            if (!ModelState.IsValid)
            {
                return(Error(ModelState));
            }

            var service = Entities.Service.Find(Id: Model.ServiceId);

            if (service == null)
            {
                return(Error("Invalid service selected"));
            }

            var booking = new Entities.Booking
            {
                DestinationLatitude  = Model.DestinationLatitude,
                Destination          = Model.Destination,
                DestinationLongitude = Model.DestinationLongitude,
                ForId                 = Model.ForId,
                IncludeFuel           = Model.IncludeFuel,
                Latitude              = Model.Latitude,
                Location              = Model.Location,
                Longitude             = Model.Longitude,
                Quantity              = Model.Quantity,
                Service               = service,
                Listing               = service.Listing,
                StartDate             = Model.StartDate,
                EndDate               = Model.EndDate,
                StatusId              = Entities.BookingStatus.Pending,
                User                  = CurrentUser,
                AdditionalInformation = Model.AdditionalInformation,
                TotalVolume           = Model.TotalVolume,
                HireCost              = Model.HireCost,
                FuelCost              = Model.FuelCost,
                TransportCost         = Model.TransportCost,
                Price                 = Model.HireCost + Model.FuelCost + Model.TransportCost,
                Distance              = Model.Distance,
                TransportDistance     = Model.TransportDistance
            };

            if (booking.Save())
            {
                Entities.Counter.Hit(CurrentUser.Id, Entities.Counters.Book, booking.Service.CategoryId);

                new Entities.Notification
                {
                    Booking = booking,
                    GroupId = Entities.NotificationGroup.Offering,
                    TypeId  = Entities.NotificationType.NewBooking,
                    User    = Entities.User.Find(Id: booking.Listing.UserId)
                }.Save(Notify: true);

                new Entities.Notification
                {
                    Booking = booking,
                    GroupId = Entities.NotificationGroup.Seeking,
                    TypeId  = Entities.NotificationType.NewBooking,
                    User    = CurrentUser
                }.Save(Notify: false);

                return(Success(new
                {
                    Booking = booking.Json()
                }));
            }

            return(Error("An unknown error occurred"));
        }