Ejemplo n.º 1
0
        public async Task CreateOfferShoulReturnTrue()
        {
            var serviceInstance = new OfferServices(context,
                                                    imageServices.Object,
                                                    cloudinaryServices.Object,
                                                    userServices.Object,
                                                    referenceNumberGenerator.Object,
                                                    mapper
                                                    );

            string realEstateId = "myRealEstateId4";
            string authorId     = "coolUniqueId3";
            var    offerToAdd   = new OfferCreateServiceModel
            {
                OfferType               = "Продажба",
                Comments                = "Some important comments",
                ContactNumber           = "0888607796",
                AgentName               = "Pesho",
                OfferServiceInformation = "Some Owner telephone number 012345678"
            };

            var actualResult = await serviceInstance.CreateOfferAsync(authorId, realEstateId, offerToAdd);

            Assert.IsTrue(actualResult, ExpectedTrueTestResultMessage);
        }
Ejemplo n.º 2
0
        public byte[] GetAgreementReport(int OfferId, int UserId)
        {
            byte[] file = null;

            //get offer data
            OfferServices OfferServ = new OfferServices();
            OfferModel    offerData = new OfferModel();

            offerData = OfferServ.GetById(OfferId);
            if (offerData == null)
            {
                throw new Exception("NOT_FOUND");
            }
            if (UserId != offerData.VesselAdmin.UserId && UserId != offerData.ProjectAdmin.UserId)
            {
                throw new Exception("UNAUTHORIZED");
            }

            if (UserId == offerData.VesselAdmin.UserId)
            {
                file = AgreementReportFile(OfferId, (int)TypeUser.Vessel);
            }
            else if (UserId == offerData.ProjectAdmin.UserId)
            {
                file = AgreementReportFile(OfferId, (int)TypeUser.Project);
            }

            return(file);
        }
Ejemplo n.º 3
0
        public ActionResult Partial(int ReferenceId)
        {
            MessageServices services      = new MessageServices();
            OfferServices   offerServices = new OfferServices();
            MessageServices chatServices  = new MessageServices();
            MessageModel    filter        = new MessageModel();

            chatServices.MarkAsReaded(
                new MessageModel()
            {
                ReferenceId = ReferenceId, From = SessionWeb.User.PersonId
            });

            OfferModel offer = offerServices.GetFirst(new OfferModel()
            {
                OfferId = ReferenceId
            });

            ViewBag.Alias = SessionWeb.User.PersonId == offer.ProjectAdmin.PersonId ? "PROJECT_OWNER"
                : SessionWeb.User.PersonId == offer.VesselAdmin.PersonId ? "VESSEL_OWNER" : "";
            ViewBag.From = SessionWeb.User.PersonId;
            ViewBag.To   = SessionWeb.User.PersonId == offer.ProjectAdmin.PersonId ? offer.VesselAdmin.PersonId
                : SessionWeb.User.PersonId == offer.VesselAdmin.PersonId ? offer.ProjectAdmin.PersonId : -1;
            ViewBag.lstMsg          = services.Get(filter);
            ViewBag.SessionPersonId = SessionWeb.User.PersonId;
            ViewBag.ReferenceId     = ReferenceId;

            return(View());
        }
Ejemplo n.º 4
0
        public async Task EditOfferShouldReturnTrue()
        {
            var mapper = this.GetMapper();

            var offerToEdit = this.TestData.FirstOrDefault();
            var mappedOffer = mapper.Map <OfferEditServiceModel>(offerToEdit);

            string comment   = "This brandly new comment";
            string agentName = "Rado";

            mappedOffer.Comments  = comment;
            mappedOffer.AgentName = agentName;

            var serviceInstance = new OfferServices(context,
                                                    imageServices.Object,
                                                    cloudinaryServices.Object,
                                                    userServices.Object,
                                                    referenceNumberGenerator.Object,
                                                    mapper
                                                    );

            var actualResult = await serviceInstance.EditOfferAsync(mappedOffer);

            Assert.IsTrue(actualResult);
            Assert.That(offerToEdit.Comments == comment && offerToEdit.AgentName == agentName);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OffersController"/> class.
 /// </summary>
 /// <param name="offersRepository">The offers repository.</param>
 /// <param name="applicationConfigRepository">The application configuration repository.</param>
 /// <param name="usersRepository">The users repository.</param>
 /// <param name="valueTypesRepository">The value types repository.</param>
 /// <param name="offersAttributeRepository">The offers attribute repository.</param>
 /// <param name="logger">The logger.</param>
 public OffersController(IOffersRepository offersRepository, IApplicationConfigRepository applicationConfigRepository, IUsersRepository usersRepository, IValueTypesRepository valueTypesRepository, IOfferAttributesRepository offersAttributeRepository, ILogger <OffersController> logger)
 {
     this.offersRepository            = offersRepository;
     this.applicationConfigRepository = applicationConfigRepository;
     this.usersRepository             = usersRepository;
     this.valueTypesRepository        = valueTypesRepository;
     this.offersService             = new OfferServices(this.offersRepository);
     this.offersAttributeRepository = offersAttributeRepository;
     this.logger = logger;
 }
        public SelectConfirmPage(OfferServices ServiceConfirm, string Id_Servicess, string UserIdd, string Titlee, string Descriptionn, string InputEntry,
                                 string Longitude, string Latitude, string reverseGeocodedOutputLabell)
        {
            InitializeComponent();

            PriceLabel.Text = ServiceConfirm.Price;

            UserId.Text      = UserIdd;
            Id_Services.Text = Id_Servicess;
            Title.Text       = Titlee;
            Description.Text = Descriptionn;
            reverseGeocodedOutputLabel.Text = reverseGeocodedOutputLabell;
        }
Ejemplo n.º 7
0
        public void GetOfferIdByRealEstateIdShouldThrowExceptionUponInvalidParameterPassed()
        {
            var realEstateId = "";

            var serviceInstance = new OfferServices(context,
                                                    imageServices.Object,
                                                    cloudinaryServices.Object,
                                                    userServices.Object,
                                                    referenceNumberGenerator.Object,
                                                    mapper
                                                    );

            Assert.ThrowsAsync <ArgumentNullException>(async() => serviceInstance.GetOfferIdByRealEstateIdAsync(realEstateId), ArgumentNullExceptonMessage);
        }
Ejemplo n.º 8
0
        public void GetOfferByIdShouldThrowExceptionIfNoSuchOffer()
        {
            string offerId = "completelyInvalidId";

            var serviceInstance = new OfferServices(context,
                                                    imageServices.Object,
                                                    cloudinaryServices.Object,
                                                    userServices.Object,
                                                    referenceNumberGenerator.Object,
                                                    mapper
                                                    );

            Assert.ThrowsAsync <ArgumentNullException>(() => serviceInstance.GetOfferByIdAsync(offerId));
        }
Ejemplo n.º 9
0
        public void ActivateOfferShouldThrowsException()
        {
            var mapper         = this.GetMapper();
            var invalidOfferId = "invalid";

            var serviceInstance = new OfferServices(context,
                                                    imageServices.Object,
                                                    cloudinaryServices.Object,
                                                    userServices.Object,
                                                    referenceNumberGenerator.Object,
                                                    mapper
                                                    );

            Assert.ThrowsAsync <ArgumentNullException>(async() => await serviceInstance.ActivateOfferAsync(invalidOfferId), ArgumentNullExceptonMessage);
        }
Ejemplo n.º 10
0
        public async Task GetOfferByIdShouldReturnServiceModel()
        {
            var    offerToGet = this.TestData.FirstOrDefault();
            string offerId    = offerToGet.Id;

            var serviceInstance = new OfferServices(context,
                                                    imageServices.Object,
                                                    cloudinaryServices.Object,
                                                    userServices.Object,
                                                    referenceNumberGenerator.Object,
                                                    mapper
                                                    );

            var returnedOffers = await serviceInstance.GetOfferByIdAsync(offerId);

            Assert.IsTrue(returnedOffers.Id.Equals(offerId), ExpectedTrueTestResultMessage);
            Assert.IsTrue(returnedOffers.OfferType.Equals(offerToGet.OfferType.ToString()), ExpectedTrueTestResultMessage);
        }
Ejemplo n.º 11
0
        public ActionResult Offers(int id)
        {
            OfferServices serv            = new OfferServices();
            PagerModel    pagerParameters = new PagerModel();

            var offertF = new OfferModel()
            {
                UserId = PersonSessionId,
            };

            if (id != 0 && id != 1)
            {
                offertF.OfferReceived = id == 2;
            }
            var results = serv.GetAll(pagerParameters, offertF);

            return(Json(results, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 12
0
        public async Task ActivateOfferShouldReturnTrue()
        {
            var mapper                 = this.GetMapper();
            var offerToActivate        = this.TestData.LastOrDefault();
            var expectedPropertyResult = true;

            var serviceInstance = new OfferServices(context,
                                                    imageServices.Object,
                                                    cloudinaryServices.Object,
                                                    userServices.Object,
                                                    referenceNumberGenerator.Object,
                                                    mapper
                                                    );

            var actualResult = await serviceInstance.ActivateOfferAsync(offerToActivate.Id);

            Assert.IsTrue(actualResult);
            Assert.That(offerToActivate.IsOfferActive == expectedPropertyResult, ExpectedTrueTestResultMessage);
        }
Ejemplo n.º 13
0
        public void EditOfferIdShouldThrowExceptionIfNoSuchOffer()
        {
            string invalidId            = "completelyInvalidId";
            var    unexistingOfferModel = new OfferEditServiceModel
            {
                Id        = invalidId,
                Comments  = "Some comments",
                OfferType = "Sale",
            };


            var serviceInstance = new OfferServices(context,
                                                    imageServices.Object,
                                                    cloudinaryServices.Object,
                                                    userServices.Object,
                                                    referenceNumberGenerator.Object,
                                                    mapper
                                                    );

            Assert.ThrowsAsync <ArgumentNullException>(() => serviceInstance.EditOfferAsync(unexistingOfferModel), ArgumentNullExceptonMessage);
        }
Ejemplo n.º 14
0
        public ActionResult UpdateVesselCost(OfferCostModel cost)
        {
            OfferServices ser = new OfferServices();

            try
            {
                var res = ser.UpdCost(cost);
                if (res.Status != Status.Success)
                {
                    throw new Exception(string.Format("{0}: {1}", "Error al actualizar costos", res.Message));
                }
                return(Json(res, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                Response.StatusCode        = (int)HttpStatusCode.BadRequest;
                Response.StatusDescription = ex.Message;

                return(Json(ex.Message, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 15
0
        public void CreateOfferShoulThrowWexeptionIfRealEstateIdIsInvalid()
        {
            var serviceInstance = new OfferServices(context,
                                                    imageServices.Object,
                                                    cloudinaryServices.Object,
                                                    userServices.Object,
                                                    referenceNumberGenerator.Object,
                                                    mapper
                                                    );

            string invalidRealEstateId = "";
            string authorId            = "coolUniqueId3";
            var    offerToAdd          = new OfferCreateServiceModel
            {
                OfferType     = "Продажба",
                Comments      = "Some important comments",
                ContactNumber = "0888607796",
            };

            Assert.ThrowsAsync <ArgumentNullException>(async() => await serviceInstance.CreateOfferAsync(authorId, invalidRealEstateId, offerToAdd), ArgumentNullExceptonMessage);
        }
Ejemplo n.º 16
0
        public ActionResult TransactionOffers(string id)
        {
            RequestResult <List <AlertModel> > result = new RequestResult <List <AlertModel> >()
            {
                Status = Status.Success
            };
            OfferServices services = new OfferServices();
            OfferModel    model    = new OfferModel();

            if (id == "offer")
            {
                model.Project.ProjectId     = 13;
                model.Vessel.VesselId       = 1;
                model.ProjectAdmin.PersonId = SessionWeb.User.PersonId;
                model.UserModifiedId        = SessionWeb.User.PersonId;
                result = services.InsComplete(model);
            }
            else if (id == "accept")
            {
                model.OfferId = 2;
                result        = services.Accept(model, (int)SessionWeb.User.PersonId);
            }

            if (result.Status == Status.Success)
            {
                foreach (AlertModel alert in result.Data)
                {
                    var context = GlobalHost.ConnectionManager.GetHubContext <AlertHub>();
                    context.Clients.Group(string.Format("P{0}", alert.To))
                    .newAlert(alert);
                }
            }

            result.Data = null;
            return(Json(result));
        }
        internal void Offerer(Database.Database dBase)
        {
            Console.WriteLine("Welcome As An Offerer > > >");
            Console.WriteLine("Enter Your Username : "******"You Cannot Be A Offerer. . . .");
                    return;
                }
                Offering offerring = new UserServices().GetPreviousCreatedOffer(dBase, user.Id);
                if (offerring != null)
                {
                    Console.WriteLine("You Are Already In Service . . .");
                    List <Booking> bookings = new BookingServices().GetAllRequestedBooking(dBase, offerring);
                    if (bookings != null)
                    {
                        int count = 0;
                        foreach (Booking booking in bookings)
                        {
                            Console.WriteLine(++count + ". " + booking.ToString());
                        }
                        count = 0;
                        Console.ReadKey(false);
                        Console.WriteLine("*************************************");
                        foreach (Booking booking in bookings)
                        {
                            if (offerring.Cardetails.LeftSeats == 0)
                            {
                                Console.WriteLine("No More Request Can Be Procees . . .");
                                bookings.RemoveAll(element => element.BookingStatus == BookingStatus.REJECTED || element.BookingStatus == BookingStatus.BROADCAST || element.BookingStatus == BookingStatus.ACCEPTED);
                                if (bookings.Count != 0)
                                {
                                    foreach (Booking bookingDestroying in bookings)
                                    {
                                        bookingDestroying.BookingStatus = BookingStatus.DESTROYED;
                                    }
                                }
                                break;
                            }
                            Console.WriteLine("Applicant Id : " + booking.UserId + "\n" + booking.JourneyDetails + "\n< < < Do you Want To Accept > > >");
                            char select = Console.ReadLine()[0];
                            count++;
                            if (select == 'Y' || select == 'y')
                            {
                                if (booking.BookingStatus == BookingStatus.BROADCAST)
                                {
                                    booking.OffererId = user.Id;
                                }
                                else
                                {
                                    new BookingServices().Accept(dBase, offerring, booking);
                                }
                                new VechicleService().ProvideASeat(offerring.Cardetails);
                                new OfferServices().Apply(booking, offerring.Discount);
                                Console.WriteLine("...Booked...");
                                continue;
                            }
                            else
                            {
                                if (booking.BookingStatus == BookingStatus.PENDING)
                                {
                                    booking.BookingStatus = BookingStatus.REJECTED;
                                    new BookingServices().RejectARequest(booking, offerring.Cardetails);
                                    Console.WriteLine("...Rejected...");
                                }
                                else
                                {
                                    //****************************NOT ACCEPTED**********************
                                }
                            }
                        }

                        Console.WriteLine("People May Be Waiting For You . . .");
                        Console.WriteLine("*************************************");
                    }
                    else
                    {
                        if (offerring.CurrentLocation == offerring.JourneyDetails.Destination)
                        {
                            new BookingServices().DestroyAllPreviousBooking(dBase, offerring, offerring.JourneyDetails.Destination, (offerring.JourneyDetails.Destination - offerring.JourneyDetails.Source > 0));
                            Console.WriteLine("Thank You For Your Suppport...");
                            offerring.Active = false;
                            Console.WriteLine("Your Total Earning Is : " + offerring.TotalEarning);
                        }
                        else
                        {
                            Console.WriteLine("You are already in service . . .");
                            Console.WriteLine("Do You Reach Your Destination . . .");
                            char IsReach = Console.ReadLine()[0];
                            if (IsReach == 'Y' || IsReach == 'y')
                            {
                                new BookingServices().DestroyAllPreviousBooking(dBase, offerring, offerring.JourneyDetails.Destination, (offerring.JourneyDetails.Destination - offerring.JourneyDetails.Source) > 0);
                                Console.WriteLine("Thank You For Your Suppport...");
                                offerring.Active = false;
                                Console.WriteLine("Your Total Earning Is : " + offerring.TotalEarning);
                            }
                            else
                            {
                                Console.WriteLine("Your Current Location Is : " + Enum.GetName(typeof(Address), offerring.CurrentLocation));
                            }
                        }
                    }
                }
                else
                {
                    Offering offering = new OfferServices().Create(dBase, user.Id);
                    offering.Active = true;
                    Console.WriteLine("Welcome," + user.Name + "\nEnter Your Car Details->>\nEnter Number Plate : ");
                    string carNumber = new Exceptions().InputAtLeastOneCharacter();

                    Console.WriteLine("Enter Maximum Seats Of Your Car : ");
                    int maxSeats = new Exceptions().InputOnlyInteger();
                    Console.WriteLine("Enter Number Of Seats You Want To Pool.");
                    int numOfSeatsToPool = new Exceptions().InputOnlyInteger();;

                    while (numOfSeatsToPool > maxSeats)
                    {
                        Console.WriteLine("Please, Enter Less Seats To Offfer . . .");
                        numOfSeatsToPool = new Exceptions().InputOnlyInteger();
                    }
                    offering.Cardetails.MaxOfferSeats = numOfSeatsToPool;
                    offering.Cardetails.LeftSeats     = numOfSeatsToPool;
                    offering.Cardetails.Number        = carNumber;
                    offering.Cardetails.MaxSeats      = maxSeats;
                    Console.WriteLine("Enter Your Start Point : ");
                    for (int i = 1; i <= Enum.GetValues(typeof(Address)).Length; i++)
                    {
                        Console.WriteLine((i) + ". " + Enum.GetName(typeof(Address), i));
                    }

                    Console.WriteLine("Enter your source : ");
                    int choices;
                    while (true)
                    {
                        choices = Int32.Parse(Console.ReadLine());
                        if (choices <= Enum.GetValues(typeof(Address)).Length)
                        {
                            break;
                        }
                        else
                        {
                            Console.WriteLine("Please, Enter A Valid Choice : ");
                            continue;
                        }
                    }
                    offering.JourneyDetails.Source = (Address)(choices);
                    offering.CurrentLocation       = offering.JourneyDetails.Source;
                    Console.WriteLine("Enter your destination : ");
                    while (true)
                    {
                        choices = Int32.Parse(Console.ReadLine());
                        if (choices <= Enum.GetValues(typeof(Address)).Length&& choices != (int)offering.JourneyDetails.Source)
                        {
                            break;
                        }
                        else
                        {
                            Console.WriteLine("Please, Enter A Valid Choice : ");
                            continue;
                        }
                    }
                    offering.JourneyDetails.Destination = (Address)(choices);
                    Console.WriteLine("Enter Fare Price Per Kilometer : ");

                    float price;
                    while (true)
                    {
                        try
                        {
                            price = float.Parse(Console.ReadLine());
                            break;
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Please, Enter A Decimal Value : ");
                            continue;
                        }
                    }
                    offering.JourneyDetails.Price = price;
                    Console.WriteLine("Choose A Offer :\n-->1.5% DISCOUNT\n-->2.10% DISCOUNT\n-->3.20% DISCOUNT");
                    char offerChoice = Console.ReadLine()[0];
                    if (offerChoice == '2')
                    {
                        offering.Discount = Discount.DISCOUNT_10P;
                    }
                    else if (offerChoice == '3')
                    {
                        offering.Discount = Discount.DISCOUNT_20P;
                    }
                    else
                    {
                        offering.Discount = Discount.DISCOUNT_5P;
                    }
                }
            }
            else
            {
                Console.WriteLine("No Such Account Exists!!!");
            }
        }
        internal void Applicant(Database.Database dBase)
        {
            Console.WriteLine("Welcome As An Applicant > > >");
            Console.WriteLine("Enter Your Username : "******"You Cannot Be An Applicant . . .");
                    return;
                }
                Booking booking = new UserServices().GetBookingByUserId(dBase, user.Id);
                if (booking != null && booking.BookingStatus == BookingStatus.PENDING)
                {
                    Console.WriteLine("You Are In Pending . . .\n<<Do You Want To Cancel(Y/N)>>");
                    key = Console.ReadKey(true);
                    if (key.KeyChar == 'Y' || key.KeyChar == 'y')
                    {
                        Offering offerer = new OfferServices().GetByUserId(dBase, booking.OffererId);
                        new VechicleService().DedeuctASeat(offerer.Cardetails);
                        offerer.TotalEarning -= booking.JourneyDetails.Price;
                        booking.BookingStatus = BookingStatus.NOTREQUESTED;
                        Console.WriteLine("Choose A New Offer Next Time! . . .");
                        return;
                    }

                    new BookingServices().DestroyAllPreviousBooking(dBase, new UserServices().GetPreviousCreatedOffer(dBase, booking.OffererId),
                                                                    new UserServices().GetPreviousCreatedOffer(dBase, booking.OffererId).CurrentLocation, (booking.JourneyDetails.Destination - booking.JourneyDetails.Source > 0));
                    if (dBase.Bookings.Contains(booking))
                    {
                        if (new UserServices().GetPreviousCreatedOffer(dBase, booking.OffererId).Cardetails.LeftSeats == 0)
                        {
                            Console.WriteLine("No Space,Aborting Your Request. . .");
                            booking.BookingStatus = BookingStatus.DESTROYED;
                        }
                        else
                        {
                            Console.WriteLine("Wait For The Guy To Accept Your Request . . .");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Sorry, Your Request Is Discarded . . .");
                        new BookingServices().Removed(booking);
                        Console.WriteLine("Check other Offers Next Time. . .");
                    }
                }
                else if (booking != null && booking.BookingStatus == BookingStatus.DESTROYED)
                {
                    Console.WriteLine("Your Fare Was : " + booking.JourneyDetails.Price);
                    new BookingServices().Removed(booking);
                }
                else if (booking != null && new UserServices().GetBookingByUserId(dBase, user.Id).BookingStatus == BookingStatus.ACCEPTED)
                {
                    Console.WriteLine("Your Request Is Accepted . . .");
                    User offerer = new UserServices().GetUserByUserId(dBase, booking.OffererId);
                    Console.WriteLine("You Have Been  Accepted By : " + offerer.Name);
                    Console.WriteLine("Did You Reach Your Destination(Y/N) : ");
                    char select = Console.ReadLine()[0];
                    if (select == 'y' || select == 'Y')
                    {
                        Offering offerring = new UserServices().GetPreviousCreatedOffer(dBase, booking.OffererId);
                        if (booking.JourneyDetails.Destination >= offerring.CurrentLocation)
                        {
                            offerring.CurrentLocation = booking.JourneyDetails.Destination;
                        }
                        offerring.TotalEarning += booking.JourneyDetails.Price;
                        new VechicleService().DedeuctASeat(offerring.Cardetails);
                        Console.WriteLine("Your Fare Price Is : " + booking.JourneyDetails.Price);
                        new BookingServices().DestroyAllPreviousBooking(dBase, offerring, booking.JourneyDetails.Destination, (booking.JourneyDetails.Destination - booking.JourneyDetails.Source > 0));
                    }
                }
                else if (booking != null && booking.BookingStatus == BookingStatus.REJECTED)
                {
                    Console.WriteLine("Your Request Was Rejected . . .Try Some Other Offer Again");
                    new BookingServices().Removed(booking);
                }
                else if (booking != null && booking.BookingStatus == BookingStatus.BROADCAST)
                {
                    if (booking.OffererId != null)
                    {
                        Console.WriteLine("Do You Wnat To Cancel Tour Accepted Request . . .");
                        char decision = Console.ReadLine()[0];
                        if (decision == 'Y' || decision == 'y')
                        {
                            new BookingServices().CancelABookingByOffererId(dBase, booking.OffererId, booking);
                        }
                        else
                        {
                            booking.BookingStatus = BookingStatus.ACCEPTED;
                        }
                    }
                    else
                    {
                        Console.WriteLine("Your Are Still In BroadCast, Wait Or Cancel ?\n1.Wait\t2.Cancel ");
                        char decision = Console.ReadLine()[0];
                        if (decision == '1')
                        {
                            Console.WriteLine("Please, Wait For Some User");
                        }
                        else
                        {
                            new BookingServices().Removed(booking);
                        }
                    }
                }
                else
                {
                    for (int i = 1; i <= Enum.GetValues(typeof(Address)).Length; i++)
                    {
                        Console.WriteLine((i) + ". " + Enum.GetName(typeof(Address), i));
                    }
                    Console.WriteLine("Enter your source : ");
                    int selectRoute;
                    while (true)
                    {
                        selectRoute = Int32.Parse(Console.ReadLine());
                        if (selectRoute <= Enum.GetValues(typeof(Address)).Length)
                        {
                            break;
                        }
                        else
                        {
                            Console.WriteLine("Please, Enter A Valid Choice : ");
                            continue;
                        }
                    }
                    Address Source = (Address)(selectRoute);
                    Console.WriteLine("Enter your destination : ");
                    while (true)
                    {
                        selectRoute = Int32.Parse(Console.ReadLine());
                        if (selectRoute != (int)Source && selectRoute <= Enum.GetValues(typeof(Address)).Length)
                        {
                            break;
                        }
                        else
                        {
                            Console.WriteLine("Please, Enter A Valid Choice : ");
                            continue;
                        }
                    }
                    Address Destination = (Address)(selectRoute);
                    Console.WriteLine("1.Book A Ride\t2.View A Ride\tE.Exit");
                    char            applicantChoice = Console.ReadLine()[0];
                    List <Offering> offerrings      = new OfferServices().GetAllOffersWithinReach(dBase, Source, Destination);
                    switch (applicantChoice)
                    {
                    case '1':
                    {
                        if (offerrings == null)
                        {
                            Console.WriteLine("No Pool Exists!!!");
                            Console.WriteLine("Do You Want To Pass A Ride?(Y/N)");
                            char decision = Console.ReadLine()[0];
                            if (decision == 'y' || decision == 'Y')
                            {
                                new BookingServices().PassBooking(dBase, user, Source, Destination);
                                Console.WriteLine("Wait For Some Offerer To Accept . . .");
                                break;
                            }
                            Console.WriteLine("Logging Out !!!");
                            return;
                        }
                        // *********************************************
                        foreach (Offering offering in offerrings)
                        {
                            User tempUser = new UserServices().GetUserByUserId(dBase, offering.UserId);
                            Console.WriteLine(offering.UserId + "\nName : " + tempUser.Name + " " + offering.ToString());
                        }
                        Console.WriteLine("Enter The UserId Of Offerer : ");
                        string   pollerUserid = Console.ReadLine();
                        Offering offer        = new UserServices().GetPreviousCreatedOffer(dBase, pollerUserid);
                        bool     haveSpace    = new VechicleService().ProvideASeat(offer.Cardetails);
                        if (haveSpace)
                        {
                            if (offer != null)
                            {
                                new BookingServices().Book(dBase, offer, Source, Destination, user.Id);
                                Console.WriteLine("Booked A Car,You are in pending, wait for few minutes to be accepted by the " + new UserServices().GetUserByUserId(dBase, pollerUserid).Name);
                            }
                            else
                            {
                                Console.WriteLine("Poller Do Not Exists");
                            }
                        }
                        else
                        {
                            new BookingServices().Book(dBase, offer, Source, Destination, user.Id);
                            Console.WriteLine("Wait,Or Cancel The Reuest . . .");
                        }
                    }
                    break;

                    case '2':
                        if (offerrings != null)
                        {
                            foreach (Offering offering in offerrings)
                            {
                                User tempUser = new UserServices().GetUserByUserId(dBase, offering.UserId);
                                Console.WriteLine(offering.UserId + "\nName : " + tempUser.Name + " " + offering.ToString());
                            }
                            Console.ReadKey(false);
                        }
                        else
                        {
                            Console.WriteLine("No Pool Exists !!!");
                        }
                        break;

                    default:
                        Console.WriteLine("Logging Out");
                        return;
                    }
                }
            }

            else
            {
                Console.WriteLine("No Such Account Exists!!!");
            }
        }
Ejemplo n.º 19
0
        public ActionResult OfferTransaction(string id, OfferModel offer)
        {
            RequestResult <List <AlertModel> > result = new RequestResult <List <AlertModel> >()
            {
                Status = Status.Success
            };
            List <AlertModel>     lstAlertToProjectCompany = new List <AlertModel>();
            List <AlertModel>     lstAlertToVesselCompany  = new List <AlertModel>();
            OfferServices         services         = new OfferServices();
            AlertTemplateServices templateServices = new AlertTemplateServices();
            AlertServices         alertServices    = new AlertServices();

            try
            {
                OfferModel val = new OfferModel();

                if (offer.OfferId != null)
                {
                    val = services.GetById((int)offer.OfferId);
                    if (val == null)
                    {
                        throw new Exception("NOT_FOUND");
                    }
                }

                if (id.ToLower() == "offer")
                {
                    offer.ProjectAdmin.PersonId = SessionWeb.User.PersonId;
                    offer.UserModifiedId        = SessionWeb.User.PersonId;
                    result = services.InsComplete(offer);

                    Dictionary <string, string> values = new Dictionary <string, string>();
                    values.Add("ID", offer.Vessel.VesselId.ToString());
                    AlertTemplateModel template = templateServices.GetById(8);
                    AlertModel         alert    = alertServices.GetWithValues(template, values);
                    lstAlertToProjectCompany.Add(alert);

                    //Trick the form how i get the offer
                    val = services.GetById((int)offer.OfferId);
                }
                else if (id.ToLower() == "accept")
                {
                    offer.VesselAdmin.PersonId = SessionWeb.User.PersonId;
                    offer.UserModifiedId       = SessionWeb.User.PersonId;
                    result = services.Accept(offer, (int)SessionWeb.User.PersonId);

                    Dictionary <string, string> values = new Dictionary <string, string>();
                    values.Add("ID", "" + val.Project.ProjectId);
                    AlertTemplateModel template = templateServices.GetById(10);
                    AlertModel         alert    = alertServices.GetWithValues(template, values);
                    lstAlertToProjectCompany.Add(alert);

                    Dictionary <string, string> values2 = new Dictionary <string, string>();
                    values2.Add("ID", PersonSessionId.ToString());
                    AlertTemplateModel template2 = templateServices.GetById(11);
                    AlertModel         alert2    = alertServices.GetWithValues(template2, values2);
                    lstAlertToVesselCompany.Add(alert2);
                }
                else if (id.ToLower() == "reject")
                {
                    offer.VesselAdmin.PersonId = SessionWeb.User.PersonId;
                    offer.UserModifiedId       = SessionWeb.User.PersonId;
                    result = services.Reject(offer);

                    Dictionary <string, string> values2 = new Dictionary <string, string>();
                    values2.Add("ID", PersonSessionId.ToString());
                    AlertTemplateModel template2 = templateServices.GetById(11);
                    AlertModel         alert2    = alertServices.GetWithValues(template2, values2);
                    lstAlertToVesselCompany.Add(alert2);
                }
                else if (id.ToLower() == "fix")
                {
                    MessageServices chatServices = new MessageServices();
                    offer.VesselAdmin.PersonId = SessionWeb.User.PersonId;
                    offer.UserModifiedId       = SessionWeb.User.PersonId;

                    if (val.Status == OfferModel.FIX && val.VesselAdmin.PersonId == SessionWeb.User.PersonId)
                    {
                        chatServices.MarkAsReaded(
                            new MessageModel()
                        {
                            ReferenceId = offer.OfferId, From = SessionWeb.User.PersonId
                        });
                        return(Json(result));
                    }

                    if (val.Status == OfferModel.NEW)
                    {
                        result = services.Fix(offer);

                        Dictionary <string, string> values = new Dictionary <string, string>();
                        values.Add("ID", offer.OfferId.ToString());
                        AlertTemplateModel template = templateServices.GetById(9);
                        AlertModel         alert    = alertServices.GetWithValues(template, values);
                        alert.To = val.ProjectAdmin.PersonId;
                        result.Data.Add(alert);

                        Dictionary <string, string> values2 = new Dictionary <string, string>();
                        values2.Add("ID", PersonSessionId.ToString());
                        AlertTemplateModel template2 = templateServices.GetById(11);
                        AlertModel         alert2    = alertServices.GetWithValues(template2, values2);
                        lstAlertToVesselCompany.Add(alert2);
                    }
                }

                if (result.Status == Status.Success)
                {
                    var context = GlobalHost.ConnectionManager.GetHubContext <AlertHub>();

                    foreach (AlertModel alert in result.Data)
                    {
                        context.Clients.Group(string.Format("P{0}", alert.To))
                        .newAlert(alert);
                    }
                    foreach (AlertModel alert in lstAlertToProjectCompany)
                    {
                        context.Clients.Group(string.Format("C{0}", val.Project.CompanyId))
                        .newAlert(alert);
                    }
                    foreach (AlertModel alert in lstAlertToVesselCompany)
                    {
                        context.Clients.Group(string.Format("C{0}", val.Vessel.Company.CompanyId.ToString()))
                        .newAlert(alert);
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex.Message == "STATUS_NOT_VALID")
                {
                    result.Message = "La oferta ya no se encuentra disponible.";
                    result.Status  = Status.Error;
                }
                else if (ex.Message == "NOT_AVAILABILITY")
                {
                    result.Message = "El barco seleccionado, no está disponible en las fechas seleccionadas.";
                    result.Status  = Status.Warning;
                }
                else
                {
                    throw new Exception(result.Message);
                }
            }

            result.Data = null;

            return(Json(result));
        }