public async Task <ActionResult> Create(Leasor leasor)
        {
            try
            {
                // TODO: Add insert logic here
                context.Leasors.Add(leasor);
                string requesturl  = "https://maps.googleapis.com/maps/api/geocode/json?address=";
                string userAddress = System.Web.HttpUtility.UrlEncode(
                    leasor.StreetAddress + " " +
                    leasor.City + " " +
                    leasor.StateCode + " " +
                    leasor.ZipCode);
                string     apiKey   = APIKeys.GeoCodeApi;
                HttpClient client   = new HttpClient();
                var        response = await client.GetStringAsync(requesturl + userAddress + apiKey);

                JObject map = JObject.Parse(response);
                leasor.Lat = (float)map["results"][0]["geometry"]["location"]["lat"];
                leasor.Lng = (float)map["results"][0]["geometry"]["location"]["lng"];
                string id = User.Identity.GetUserId();
                leasor.ApplicationId = id;
                context.SaveChanges();

                return(RedirectToAction("Index", "Home"));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult UnRentItem()
        {
            string      appId  = User.Identity.GetUserId();
            Leasor      leasor = context.Leasors.Where(r => r.ApplicationId == appId).FirstOrDefault();
            List <Item> items  = context.Items.Where(i => i.LeasorId == leasor.LeasorId).ToList();

            foreach (Item item in items)
            {
                if (DateTime.Now >= item.EndDate)
                {
                    Renter renter = context.Renters.Where(r => r.RenterId == item.RenterId).FirstOrDefault();
                    item.Availability = true;
                    item.StartDate    = null;
                    item.EndDate      = null;
                    item.RenterId     = null;
                    RatingQueue ratingQueue = new RatingQueue();
                    ratingQueue.LeasorId = leasor.LeasorId;
                    ratingQueue.RenterId = renter.RenterId;
                    context.RatingQueues.Add(ratingQueue);
                    context.SaveChanges();
                    sendText.SendSMSToRenterForRentPeriodEnding(renter);
                    //RedirectToAction("Create", "Ratings", rating);
                }
            }
            return(RedirectToAction("Index", "Home"));
        }
        public ActionResult GetLeasorItems(int id)
        {
            Leasor      leasor      = context.Leasors.Where(l => l.LeasorId == id).FirstOrDefault();
            List <Item> leasorItems = context.Items.Where(l => l.LeasorId == leasor.LeasorId).ToList();

            return(View(leasorItems));
        }
        public ActionResult GetRatingQueue()
        {
            string             appId        = User.Identity.GetUserId();
            Leasor             leasor       = context.Leasors.Where(r => r.ApplicationId == appId).FirstOrDefault();
            List <RatingQueue> ratingQueues = context.RatingQueues.Where(r => r.LeasorId == leasor.LeasorId).ToList();

            return(View(ratingQueues));
        }
 public ActionResult Delete(int id, Leasor leasor)
 {
     try
     {
         // TODO: Add delete logic here
         Leasor leasorToDelete = context.Leasors.Where(l => l.LeasorId == id).FirstOrDefault();
         context.Leasors.Remove(leasorToDelete);
         context.SaveChanges();
         return(RedirectToAction("Index", "Home"));
     }
     catch
     {
         return(View());
     }
 }
        public ActionResult PayRequest(int id, int ItemId)
        {
            Renter      renter      = context.Renters.Where(r => r.RenterId == id).FirstOrDefault();
            Item        item        = context.Items.Where(i => i.ItemId == ItemId).FirstOrDefault();
            Transaction transaction = new Transaction();

            transaction.RenterId      = renter.RenterId;
            transaction.ItemId        = item.ItemId;
            transaction.TimeOfPayment = DateTime.Now;
            context.Transactions.Add(transaction);
            context.SaveChanges();
            Leasor leasor = context.Leasors.Where(l => l.LeasorId == item.LeasorId).FirstOrDefault();

            return(RedirectToAction("StripePayment", "Renters", item));
        }
Beispiel #7
0
        public ActionResult Index()
        {
            string userId = User.Identity.GetUserId();

            if (User.IsInRole("Leasor"))
            {
                Leasor leasor = context.Leasors.Where(e => e.ApplicationId == userId).FirstOrDefault();
                return(RedirectToAction("Details", "Leasors", new { id = leasor.LeasorId }));
            }
            else if (User.IsInRole("Renter"))
            {
                Renter renter = context.Renters.Where(c => c.ApplicationId == userId).FirstOrDefault();
                return(RedirectToAction("Details", "Renters", new { id = renter.RenterId }));
            }
            return(View());
        }
        public ActionResult SendSMSToLeasorToNotifyOfTransaction(Leasor leasor)
        {
            var accountSid = APIKeys.TwilioaccountSid;
            var authToken  = APIKeys.TwilioauthToken;

            TwilioClient.Init(accountSid, authToken);

            var to   = new PhoneNumber("+1" + leasor.PhoneNumber);
            var from = new PhoneNumber("+19285506141");

            var message = MessageResource.Create(
                to: to,
                from: from,
                body: "You have recieved a Payment for an item.");

            return(Content(message.Sid));
        }
        public ActionResult SendSMSToLeasorToNotifyRenterAddedToQueue(Leasor leasor)
        {
            var accountSid = APIKeys.TwilioaccountSid;
            var authToken  = APIKeys.TwilioauthToken;

            TwilioClient.Init(accountSid, authToken);

            var to   = new PhoneNumber("+1" + leasor.PhoneNumber);
            var from = new PhoneNumber("+19285506141");

            var message = MessageResource.Create(
                to: to,
                from: from,
                body: "You have a new renter in a queue.");

            return(Content(message.Sid));
        }
 public ActionResult Edit(int id, Leasor leasor)
 {
     try
     {
         // TODO: Add update logic here
         Leasor leasorToEdit = context.Leasors.Where(l => l.LeasorId == id).FirstOrDefault();
         leasorToEdit.FirstName     = leasor.FirstName;
         leasorToEdit.LasttName     = leasor.LasttName;
         leasorToEdit.EmailAddress  = leasor.EmailAddress;
         leasorToEdit.StreetAddress = leasor.StreetAddress;
         leasorToEdit.ZipCode       = leasor.ZipCode;
         leasorToEdit.StateCode     = leasor.StateCode;
         context.SaveChanges();
         return(RedirectToAction("Index", "Home"));
     }
     catch
     {
         return(View());
     }
 }
        public ActionResult AddSelfToQueue(int id)
        {
            var    item   = context.Items.Where(i => i.ItemId == id).FirstOrDefault();
            string appId  = User.Identity.GetUserId();
            Renter renter = context.Renters.Where(r => r.ApplicationId == appId).FirstOrDefault();
            Queue  queue  = context.Queues.Where(q => q.ItemId == item.ItemId).FirstOrDefault();

            QueueRenter queueRenter = new QueueRenter();

            context.QueueRenters.Add(queueRenter);
            queueRenter.QueueId  = queue.QueueId;
            queueRenter.RenterId = renter.RenterId;


            context.SaveChanges();
            Leasor leasor = context.Leasors.Where(l => l.LeasorId == item.LeasorId).FirstOrDefault();

            //sendText.SendSMSToLeasorToNotifyRenterAddedToQueue(leasor);
            return(RedirectToAction("Index", "Home"));
        }
        public ActionResult StripePayment(Item item)
        {
            TransactionViewModel transactionViewModel = new TransactionViewModel()
            {
                ItemName = "", ItemPrice = 0, RenterId = 0
            };
            string appId  = User.Identity.GetUserId();
            Renter renter = context.Renters.Where(r => r.ApplicationId == appId).FirstOrDefault();

            transactionViewModel.RenterId  = renter.RenterId;
            transactionViewModel.ItemName  = item.Name;
            transactionViewModel.ItemPrice = Convert.ToInt32(item.Price) * 100;
            Leasor         leasor         = context.Leasors.Where(l => l.LeasorId == item.LeasorId).FirstOrDefault();
            PaymentRequest paymentRequest = context.PaymentRequests.Where(p => p.RenterId == renter.RenterId && p.ItemId == item.ItemId).FirstOrDefault();

            context.PaymentRequests.Remove(paymentRequest);
            context.SaveChanges();
            //sendText.SendSMSToLeasorToNotifyOfTransaction(leasor);
            return(View(transactionViewModel));
        }
        // GET: Leasors/Delete/5
        public ActionResult Delete(int id)
        {
            Leasor leasor = context.Leasors.Where(l => l.LeasorId == id).FirstOrDefault();

            return(View(leasor));
        }
        // GET: Leasors/Create
        public ActionResult Create()
        {
            Leasor leasor = new Leasor();

            return(View(leasor));
        }