Exemplo n.º 1
0
        public ActionResult Create([Bind(Include = "Key,Message,Coach,PhoneNumber")] ContactCoach contactCoach)
        {
            if (ModelState.IsValid)
            {
                string user      = User.Identity.GetUserId();
                var    result    = from row in db.Players where row.UserId == user select row;
                var    rowResult = result.FirstOrDefault();
                //rowResult.CoachID = contactCoach.Coach;
                var coachResult    = from row in db.Coaches where row.CoachID == rowResult.CoachID select row;
                var coachRowResult = coachResult.FirstOrDefault();
                contactCoach.PhoneNumber = coachRowResult.PhoneNumber;
                db.ContactCoaches.Add(contactCoach);
                db.SaveChanges();
                string  lastPhone           = (from n in db.ContactCoaches orderby n.PhoneNumber descending select n.PhoneNumber).FirstOrDefault();
                string  lastMassage         = (from n in db.ContactCoaches orderby n.Message descending select n.Message).FirstOrDefault();
                Message message             = new Message();
                HelperClasses.Twilio twilio = new HelperClasses.Twilio();
                message.content   = lastMassage;
                message.recipient = lastPhone;
                twilio.Send(message, lastPhone);
                return(RedirectToAction("Home", "Players"));
            }


            return(View(contactCoach));
        }
Exemplo n.º 2
0
        public ActionResult SentText()
        {
            Message message        = new Message();
            string  user           = User.Identity.GetUserId();
            var     coachRow       = from row in db.Coaches where row.UserId == user select row;
            var     coachRowResult = coachRow.FirstOrDefault();

            foreach (var item in db.Players)
            {
                if (item.CoachID == coachRowResult.CoachID)
                {
                    message.content   = "The lineups have been sent! Check if your in it now!";
                    message.recipient = item.PhoneNumber;
                    HelperClasses.Twilio twilio = new HelperClasses.Twilio();
                    twilio.Send(message, item.PhoneNumber);
                }
            }
            return(View());
        }
Exemplo n.º 3
0
 public ActionResult Create([Bind(Include = "CoachID,TeamName,FirstName,LastName,UserId,PhoneNumber,Code")] Coach coach)
 {
     if (ModelState.IsValid)
     {
         string user      = User.Identity.GetUserId();
         var    result    = from row in db.Users where row.Id == user select row;
         var    rowResult = result.FirstOrDefault();
         coach.UserId      = user;
         coach.PhoneNumber = rowResult.PhoneNumber;
         coach.Code        = GetCode();
         db.Coaches.Add(coach);
         db.SaveChanges();
         Message message = new Message();
         message.content   = "Your code is: " + coach.Code;
         message.recipient = coach.PhoneNumber;
         HelperClasses.Twilio twilio = new HelperClasses.Twilio();
         twilio.Send(message, coach.PhoneNumber);
         return(RedirectToAction("Home", "Coaches"));
     }
     return(View(coach));
 }