示例#1
0
        public ActionResult Unmatch(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            MatchedCouple match = db.Match.Find(id);

            if (match == null)
            {
                return(HttpNotFound());
            }
            //Remove from liked list also

            db.Match.Remove(match);
            db.SaveChanges();
            return(RedirectToAction("Matches", "Couple"));
        }
示例#2
0
        public ActionResult Like(string id)
        {
            var us          = User.Identity.GetUserId();
            var otherCouple = db.Couples.Where(c => c.UserName == id).FirstOrDefault();
            var thisCouple  = db.Couples.Where(c => c.CurrentUser == us).FirstOrDefault();

            Likes like = new Likes
            {
                First  = thisCouple,
                Second = otherCouple
            };

            db.Like.Add(like);

            //Couples have liked each other, creates match and sends messages
            bool magic = db.Like.Where(c => c.First.Id == otherCouple.Id && c.Second.Id == thisCouple.Id).Any();

            if (magic == true)
            {
                //Send Message with Results
                var ourPhone   = thisCouple.Phone;
                var ourName    = thisCouple.UserName;
                var z1         = thisCouple.ZipCode;
                var theirPhone = otherCouple.Phone;
                var theirName  = otherCouple.UserName;
                var z2         = otherCouple.ZipCode;

                var mess1 = $"Congrats! You've made a Table For Four match with {theirName}.  \n" +
                            "The link below will show you some restaurants located between you.  \n" +
                            $"https://www.meetways.com/halfway/'{z1}'/'{z2}'/restaurant/d";

                var mess2 = $"Congrats! You've made a Table For Four match with {ourName}.  \n" +
                            "The link below will show you some restaurants located between you.  \n" +
                            $"https://www.meetways.com/halfway/'{z1}'/'{z2}'/restaurant/d";

                string AccountSid = ConfigurationManager.AppSettings["TwilioSID"];
                string AuthToken  = ConfigurationManager.AppSettings["TwilioAuthToken"];
                TwilioClient.Init(AccountSid, AuthToken);

                MessageResource.Create(
                    to: new PhoneNumber(ourPhone),
                    from: new PhoneNumber("+18642077275"),
                    body: $"{mess1}");

                MessageResource.Create(
                    to: new PhoneNumber(theirPhone),
                    from: new PhoneNumber("+18642077275"),
                    body: $"{mess2}");

                MatchedCouple match = new MatchedCouple
                {
                    FirstCouple  = thisCouple.Id,
                    SecondCouple = otherCouple.Id,
                    Suggestions  = $"https://www.meetways.com/halfway/'{z1}'/'{z2}'/restaurant/d",
                };
                db.Match.Add(match);

                Messages message1 = new Messages
                {
                    Created    = DateTime.Now,
                    FromCouple = thisCouple.UserName,
                    ToCouple   = otherCouple.UserName,
                    Title      = $"Congrats! You've matched up with {thisCouple.UserName}",
                    Message    = mess1
                };
                db.Message.Add(message1);

                Messages message2 = new Messages
                {
                    Created    = DateTime.Now,
                    FromCouple = otherCouple.UserName,
                    ToCouple   = thisCouple.UserName,
                    Title      = $"Congrats! You've matched up with {otherCouple.UserName}",
                    Message    = mess2
                };
                db.Message.Add(message2);
            }

            db.SaveChanges();
            var last = System.Web.HttpContext.Current.Request.UrlReferrer.ToString();

            return(Redirect(last));
        }