public IActionResult CheckCustomerReview([FromQuery] int id, string userid)
        {
            string   currentUserId = userid;//Get UserId
            POJOMsgs model         = new POJOMsgs();
            //Check if he booked the car.
            bool _IsMyReservation = _context.Reservations.Any(us => us.UserId == currentUserId && us.VehicleId == id);

            if (_IsMyReservation)
            {
                Review _Reviews = _context.Reviews.FirstOrDefault(m => m.VehicleId == id && m.UserId == currentUserId);
                if (_Reviews != null)
                {
                    model.Flag = true;
                    model.Msg  = "You have already reviewed this Car.";
                    return(Ok(model));
                }
                else
                {
                    model.Flag = false;
                    model.Msg  = "You dont have reviewe for this Car.";
                    return(Ok(model));
                }
            }
            else
            {
                //true to disable the review box
                model.Flag = true;
                model.Msg  = "You dont have right to reviewe  this Car, you need to book it first.";
                return(Ok(model));
            }
        }
        public async Task <IActionResult> DeleteFavorite([FromQuery] int id, string userid)
        {
            POJOMsgs model         = new POJOMsgs();
            string   currentUserId = userid;
            Favorite favorite      = new Favorite();

            try
            {
                Favorite fav = await _context.Favorites.FirstOrDefaultAsync(m => m.Id == id);

                if (currentUserId == fav.UserId)
                {
                    _context.Favorites.Remove(fav);
                    await _context.SaveChangesAsync();

                    model.Flag = true;
                    model.Msg  = "Has Been Deleted it";
                }
                else
                {
                    model.Flag = true;
                    model.Msg  = "Has Been Deleted it";
                    return(Ok(model));
                }
            }
            catch (Exception e)
            {
                model.Flag = false;
                model.Msg  = e.ToString();
            }
            return(Ok(model));
        }
        public async Task <IActionResult> AddToServiceWishList([FromQuery] int id, string userid)
        {
            POJOMsgs model         = new POJOMsgs();
            string   currentUserId = userid;
            Favorite _Favorite     = await _context.Favorites.FirstOrDefaultAsync(m => m.VehicleId == id && m.UserId == currentUserId);

            if (_Favorite != null)
            {
                model.Flag = true;
                model.Msg  = " available in db and we deleted it.";
                _context.Favorites.Remove(_Favorite);
            }
            else
            {
                Favorite _FavoriteAdd = new Favorite
                {
                    VehicleId  = id,
                    UserId     = currentUserId,
                    UpdateTime = DateTime.Now,
                    CreateTime = DateTime.Now
                };
                await _context.Favorites.AddAsync(_FavoriteAdd);

                model.Flag = false;
                model.Msg  = "not available in db and we added it.";
            }
            await _context.SaveChangesAsync();

            return(Ok(model));
        }
Exemple #4
0
        public async Task <IActionResult> SaveDrivingLicenceImage(IFormCollection form, DrivingLicence _DrivingLicence)
        {
            POJOMsgs POJO = new POJOMsgs();

            try
            {
                // string currentUserId = _userManager.GetUserId(HttpContext.User);//Get UserId
                string _imgname  = Guid.NewGuid().ToString(); //Random String To chang the Image Name
                var    webRoot   = _env.WebRootPath;
                string storePath = webRoot + "/Image/";       //The root to save the image
                if (form.Files == null || form.Files[0].Length == 0)
                {
                    return(RedirectToAction("Index"));
                }

                var filename = _imgname + form.Files[0].FileName;
                var name     = form.Files[0].Name;
                var path     = Path.Combine(
                    Directory.GetCurrentDirectory(), storePath,
                    filename);
                using (var stream = new FileStream(path, FileMode.Create))
                {
                    await form.Files[0].CopyToAsync(stream);
                }
                //Give  ImageThumbnail for DrivingLicence
                DrivingLicence model = await _context.DrivingLicences.FindAsync(_DrivingLicence.Id);

                model.UpdateTime = DateTime.Now;
                //   model.UserId = currentUserId;
                model.Image = "/Image/" + filename;
                _context.DrivingLicences.Update(model);
                await _context.SaveChangesAsync();

                POJO.Flag   = true;
                POJO.Msg    = "Has Been Added Successfully...";
                ViewBag.Msg = "Your Driving Licence has been updated";
            }
            catch (Exception e)
            {
                POJO.Flag   = false;
                POJO.Msg    = e.ToString();
                ViewBag.Msg = e.ToString();
            }
            return(Json(POJO));
        }
        public IActionResult GetServiceFavoriteCheck([FromQuery] int id, string userid)
        {
            POJOMsgs model         = new POJOMsgs();
            string   currentUserId = userid;
            bool     _IsMyFavorite = _context.Favorites.Any(m => m.VehicleId == id && m.UserId == currentUserId);

            if (_IsMyFavorite)
            {
                model.Flag = true;
                model.Msg  = "available in db";
                return(Ok(model));
            }
            else
            {
                model.Flag = false;
                model.Msg  = "not available in db";
                return(Ok(model));
            }
        }
        public async Task <IActionResult> GetAddressFromAPI([FromBody] BranchAddressModelView value)
        {
            WebSiteSetting _WebsiteSetting = await _context.WebSiteSettings.FirstOrDefaultAsync();

            string APIMyKey = _WebsiteSetting.AddressAPI;
            //Rs_5XMJYb0aGFo6VJ6Xb4w17847
            BranchAddress Myaddress = new BranchAddress();
            // var WebsiteSetting = _context.Settings.FirstOrDefault();
            var apiKey = new ApiKey(APIMyKey);

            using (var api = new GetAddesssApi(apiKey))
            {
                var result = await api.Address.Get(new GetAddressRequest(value.PostCode, value.HouseNumber));

                if (result.IsSuccess)
                {
                    var successfulResult = (GetAddressResponse.Success)result;

                    var latitude = successfulResult.Latitude;

                    var Longitude = successfulResult.Longitude;

                    foreach (var address in successfulResult.Addresses)
                    {
                        Myaddress.Street      = address.Line1 + " " + address.Line2 + " " + address.Line3 + " " + address.Line4;
                        Myaddress.City        = address.TownOrCity;
                        Myaddress.County      = address.County;
                        Myaddress.PostCode    = value.PostCode;
                        Myaddress.HouseNumber = value.HouseNumber;
                        Myaddress.Country     = "UK";
                        Myaddress.Longitute   = Longitude;
                        Myaddress.Latitue     = latitude;
                    }
                    return(Json(Myaddress));
                }
                POJOMsgs model = new POJOMsgs
                {
                    Flag = false,
                    Msg  = result.FailedResult.Raw.ToString()
                };
                return(Json(model));
            }
        }
        public async Task <IActionResult> SubmitReview([FromBody] Review _review)
        {
            POJOMsgs model         = new POJOMsgs();
            string   currentUserId = _review.UserId;//Get UserId
            Review   _Review       = new Review();

            try
            {
                _Review.Rating      = _review.Rating;
                _Review.UserId      = currentUserId;
                _Review.Description = _review.Description;
                _Review.VehicleId   = _review.VehicleId;
                _Review.CreateTime  = DateTime.Now;
                _Review.UpdateTime  = DateTime.Now;
                await _context.Reviews.AddAsync(_Review);

                await _context.SaveChangesAsync();

                model.Flag = true;
                model.Msg  = "has Been Added";

                //Calc it with the last rate value avg.(Future Method)
                IQueryable <Review> _Reviews = _context.Reviews.Where(r => r.VehicleId == _review.VehicleId);
                double AverageRating         = await _Reviews.AverageAsync(m => m.Rating);

                Vehicle _Vehicle = await _context.Vehicles.FindAsync(_review.VehicleId);

                _Vehicle.Rating     = AverageRating;
                _Vehicle.UpdateTime = DateTime.Now;
                _context.Vehicles.Update(_Vehicle);
                await _context.SaveChangesAsync();

                //Calc it with the last rate value avg.
            }
            catch (Exception e)
            {
                model.Flag = false;
                model.Msg  = e.ToString();
            }
            return(Ok(model));
        }
        public async Task <IActionResult> DeleteBranch(int id)
        {
            POJOMsgs model = new POJOMsgs();

            try
            {
                Branch _Branch = await _context.Branches.FindAsync(id);

                _context.Branches.Remove(_Branch);
                await _context.SaveChangesAsync();

                model.Flag = true;
                model.Msg  = "Has Been Deleted it";
            }
            catch (Exception e)
            {
                model.Flag = false;
                model.Msg  = e.ToString();
            }
            return(Json(model));
        }
Exemple #9
0
        public async Task <IActionResult> PayByCard(string stripeEmail, string stripeToken, CheckOutModelView data)
        {
            POJOMsgs       POJOModel      = new POJOMsgs();
            string         currentUserId  = _userManager.GetUserId(HttpContext.User);//Get UserId
            ErrorViewModel errorViewModel = new ErrorViewModel();
            //Converting to duoble
            int?_amount = 0;

            if (!string.IsNullOrEmpty(data.TotalOrder.ToString()))
            {
                double n;
                bool   isNumeric = double.TryParse(data.TotalOrder.ToString(), out n);
                _amount = isNumeric ? (int)(Convert.ToDecimal(data.TotalOrder.ToString()) * 100) : -1;
            }
            var customers = new CustomerService();
            var charges   = new ChargeService();
            var customer  = customers.Create(new CustomerCreateOptions
            {
                Email       = stripeEmail,
                SourceToken = stripeToken
            });

            Charge charge = charges.Create(new ChargeCreateOptions
            {
                Amount       = _amount,
                Description  = data.Comment,
                Currency     = "GBP",
                CustomerId   = customer.Id,
                ReceiptEmail = data.Email,//the customer will recevive email invoice from stripe service
                Metadata     = new Dictionary <String, String>()
                {
                    { "OrderId", data.OrderId.ToString() },
                    { "PostCode", data.PostCode },
                }
                ,
            });

            if (charge.Status == "succeeded")
            {
                string BalanceTransactionId = charge.BalanceTransactionId;
                CarShare.Data.Order _Order  = await _context.Orders.FindAsync(data.OrderId);

                //Get the Reservation for this order to send the details to the customer by email (Invoice).
                Reservation _Reservation = await _context.Reservations.FindAsync(_Order.ReservationId);

                try
                {
                    //change the order status to paid
                    _Order.IsPaid     = true;
                    _Order.UpdateDate = DateTime.Now;
                    await _context.SaveChangesAsync();

                    //Change the REservation to IsConfirmed =ture mean paid too
                    _Reservation.IsConfirmed = true;
                    _Reservation.UpdateTime  = DateTime.Now;
                    await _context.SaveChangesAsync();
                }
                catch (Exception e)
                {
                    POJOModel.Flag = false;
                    POJOModel.Msg  = e.ToString();
                }
                POJOModel.Flag = true;
                POJOModel.Msg  = _Order.Id.ToString();

                //Create Trans Record
                BankTransaction _BankTransaction = new BankTransaction
                {
                    TransactionId = BalanceTransactionId,
                    UserId        = currentUserId,
                    OrderId       = data.OrderId,
                    Amount        = data.TotalOrder,
                    Status        = "succeeded",
                    Date          = DateTime.Now,
                    FullName      = data.FirstName + " " + data.LastName
                };

                await _context.AddAsync(_BankTransaction);

                await _context.SaveChangesAsync();

                //Get te Vehicle Details.
                Vehicle _Vehicle = await _context.Vehicles.FindAsync(data.VehicleId);

                //Number of Hours
                int Hours = Convert.ToInt32(_Order.DropOffTime) - Convert.ToInt32(_Order.PickUpTime);
                //Send Email to the Cutomer Invoice...
                //Preper the link for Location image
                string GoogleImagePath = $"https://maps.googleapis.com/maps/api/staticmap?size=600x300&maptype=roadmap&markers=color:blue%7Clabel:S%7C{_Reservation.PickUpLocationLatitue},{_Reservation.PickUpLocationLongitute}&markers=color:green%7Clabel:E%7C{_Reservation.ReturnLocationLatitue},{_Reservation.ReturnLocationLongitute}&key=AIzaSyAJu3YwpJf6K5u1EVMtncPm4CD3209OWnw";
                EmailReceiptsBodyModelView _EmailReceipts = new EmailReceiptsBodyModelView()
                {
                    OrderNum      = data.OrderId.ToString(),
                    CustomerName  = data.FirstName + " " + data.LastName,
                    CustomerEmail = data.Email,
                    ServiceName   = _Vehicle.Model,
                    Hours         = Hours.ToString(),
                    Price         = _Vehicle.PricePerHour.ToString(),
                    Total         = data.TotalOrder.ToString(),
                    PickUpDate    = _Reservation.PickUpDate.ToShortDateString(),
                    // DropOFFDate=_Reservation.DropOffDate.ToShortDateString(),
                    PickUpTime  = _Reservation.PickUpTime + ":00",
                    DropOFFTime = _Reservation.DropOffTime + ":00",
                    MapImage    = GoogleImagePath
                };
                string EmailReciptsBody = EmailReceiptsBody(_EmailReceipts);
                await _emailSender.SendEmailAsync(data.Email, "Car Share Service", EmailReciptsBody);

                //Send SMS Confirmation
                _SMSSender.SendSMS(data.Mobile, "You Have Paid: £" + _Order.TotalAmount.ToString() + " successfully, The Vehcile REG#" + _Vehicle.Registration);

                int id = data.OrderId;
                return(RedirectToAction("OrderConfirmation", "Order", new { id = data.OrderId }));
            }
            else
            {
                ErrorViewModel error = new ErrorViewModel()
                {
                    ErrorMsg = "Your payment has been Fail... you can pay it again from Pinding Order..."
                };
                //Error page if payment not sucssefuly done
                return(RedirectToAction("Error", "Home", error));
            }

            ////Get te Vehicle Details.
            //Vehicle _Vehicle = await _context.Vehicles.FindAsync(data.VehicleId);
            ////Send Email to the Cutomer Invoice...
            //string EmailReciptsBody = EmailReceiptsBody(data.OrderId.ToString(), data.FirstName + " " + data.LastName, data.Email, _Vehicle.Model, _Vehicle.PricePerHour.ToString(), data.TotalOrder.ToString());
            //await _emailSender.SendEmailAsync(data.Email, "Car Share Service", EmailReciptsBody);
            //int id = data.OrderId;
            //return RedirectToAction("OrderConfirmation", "Order", new { id = data.OrderId });
        }
Exemple #10
0
        public async Task <IActionResult> BookIt([FromBody] AvailableVehicleModelView data)
        {
            POJOMsgs POJOmodel     = new POJOMsgs();
            string   currentUserId = _userManager.GetUserId(HttpContext.User);//Get UserId

            if (currentUserId != null)
            {
                //get the current location of the car
                //  VehicleCurrentLocation _VehicleCurrentLocation = await _context.VehicleCurrentLocations.FirstOrDefaultAsync(car =>car.VehicleId==data.VehicleId);
                try
                {
                    //GEt the user email
                    var _User = await _context.Users.FindAsync(currentUserId);

                    //GEt the vehicle details
                    Vehicle _Vehicle = await _context.Vehicles.FindAsync(data.VehicleId);

                    //Get the total hours and price
                    double TotalPrice = _Vehicle.PricePerHour * (Convert.ToInt32(data.DropOffTime) - Convert.ToInt32(data.PickUpTime));
                    // string currentUserId = _userManager.GetUserId(HttpContext.User);//Get UserId
                    Reservation model = new Reservation
                    {
                        VehicleId               = data.VehicleId,
                        PickUpLocationLatitue   = data.PickLatitue,   // car current location
                        PickUpLocationLongitute = data.PickLongitute, // car current location
                        ReturnLocationLatitue   = data.DropoffLatitue,
                        ReturnLocationLongitute = data.DropoffLongitute,
                        PickUpDate              = Convert.ToDateTime(data.PickUpDate),
                        //   DropOffDate = Convert.ToDateTime(data.DropOffDate),
                        PickUpTime  = data.PickUpTime,
                        DropOffTime = data.DropOffTime,
                        UserId      = currentUserId,
                        CreateTime  = DateTime.Now,
                        UpdateTime  = DateTime.Now,
                        Amount      = TotalPrice
                    };
                    //Adding New Reservation
                    await _context.Reservations.AddAsync(model);

                    await _context.SaveChangesAsync();

                    int _ReservationId = model.Id;
                    //to add/or update VehicleAvailabilities tb (5,2)
                    VehicleAvailability _AvailableVehicle = await _context.VehicleAvailabilities.FirstOrDefaultAsync(a => a.VehicleId == model.VehicleId && a.Date == model.PickUpDate);

                    //if avail just update it
                    if (_AvailableVehicle != null)
                    {
                        string TempBookingTime = _AvailableVehicle.BookingTime + "," + model.PickUpTime + "," + model.DropOffTime;
                        _AvailableVehicle.BookingTime = TempBookingTime;
                        _AvailableVehicle.UpdateTime  = DateTime.Now;
                        _AvailableVehicle.UserId      = currentUserId;
                        //update VehicleAvailabilities
                        _context.VehicleAvailabilities.Update(_AvailableVehicle);
                        await _context.SaveChangesAsync();
                    }
                    else
                    {
                        VehicleAvailability _availableVehicle = new VehicleAvailability
                        {
                            VehicleId   = data.VehicleId,
                            Date        = model.PickUpDate,
                            BookingTime = model.PickUpTime + "," + model.DropOffTime,
                            UserId      = currentUserId,
                            CreateTime  = DateTime.Now,
                            UpdateTime  = DateTime.Now
                        };
                        //Add new VehicleAvailabilities
                        await _context.VehicleAvailabilities.AddAsync(_availableVehicle);

                        await _context.SaveChangesAsync();
                    }



                    //after create order after booking
                    Order _Order = new Order
                    {
                        VehicleId  = data.VehicleId,
                        UserId     = currentUserId,
                        PickUpDate = Convert.ToDateTime(data.PickUpDate),
                        //   DropOffDate = Convert.ToDateTime(data.DropOffDate),
                        PickUpTime    = data.PickUpTime,
                        DropOffTime   = data.DropOffTime,
                        ReservationId = _ReservationId
                    };

                    _Order.TotalAmount = TotalPrice; //Need the total hours
                    _Order.IsPaid      = false;      //before pay
                    _Order.CreateDate  = DateTime.Now;
                    _Order.UpdateDate  = DateTime.Now;
                    await _context.Orders.AddAsync(_Order);

                    await _context.SaveChangesAsync();

                    POJOmodel.Flag = true;
                    POJOmodel.Msg  = _Order.Id.ToString();


                    //Do Job
                    IJobDetail _JobDeleteUnpaid = JobBuilder.Create <JobDeleteUnpaid>()
                                                  .UsingJobData("Id", _Order.Id.ToString())
                                                  .UsingJobData("Email", _User.Email)
                                                  .WithIdentity("simplejob" + _Order.Id.ToString(), "quartzexapmle" + _Order.Id.ToString())
                                                  .Build();

                    ITrigger _JobDeleteUnpaid_triger = TriggerBuilder.Create()
                                                       .WithIdentity("testtrigger" + _Order.Id.ToString(), "quartzexapmle" + _Order.Id.ToString())
                                                       .StartNow()
                                                       .WithSimpleSchedule(x => x.WithIntervalInMinutes(3).WithRepeatCount(2))
                                                       .Build();
                    await _scheduler.ScheduleJob(_JobDeleteUnpaid, _JobDeleteUnpaid_triger);

                    //
                }
                catch (Exception e)
                {
                    POJOmodel.Flag = false;
                    POJOmodel.Msg  = e.ToString();
                }
            }
            else
            {
                POJOmodel.Flag = false;
                POJOmodel.Msg  = "Plase, Login or Regiester....";
            }


            return(Json(POJOmodel));
        }