コード例 #1
0
        public string sendEmail(string id, string emailText)
        {
            try
            {
                if (User.Identity.IsAuthenticated)
                {
                    string      toEmail = null;
                    TripContext a       = new TripContext();

                    Trip b = a.Trips.Single(u => u.id.ToString() == id);
                    AspNetUsersContext us = new AspNetUsersContext();
                    AspNetUsers        au = us.AspNetUsers.Single(z => z.Id == b.created_by);
                    toEmail = au.Email;
                    if (SMTPSendEmail(toEmail, User.Identity.Name + " wants to carpool with you", emailText))
                    {
                        return("success");
                    }
                    else
                    {
                        return("fail");
                    }
                }
                else
                {
                    return("fail");
                }
            }
            catch
            {
                return("fail");
            }
        }
コード例 #2
0
        public string ShowJoinButton(string id)
        {
            if (tp == null)
            {
                tp = new TripContext();
            }
            try
            {
                TripGroupContext   g = new TripGroupContext();
                AspNetUsersContext u = new AspNetUsersContext();
                Trip        te       = tp.Trips.Single(a1 => a1.id.ToString() == id);
                AspNetUsers a        = u.AspNetUsers.Single(c1 => c1.Id == te.created_by);

                if (a.UserName == User.Identity.Name)
                {
                    return("1");
                }
                else if (te.vacant_seats == 0)
                {
                    return("2");
                }
                else
                {
                    return("3");
                }
            }
            catch
            {
                return("3");
            }
        }
コード例 #3
0
        public ActionResult AddTrip(Trip t)
        {
            TripContext ts = new TripContext();

            if (t.carAvailable == false)
            {
                t.vacant_seats = -1;
            }
            AspNetUsersContext us  = new AspNetUsersContext();
            AspNetUsers        asp = us.AspNetUsers.Single(a => a.Email == User.Identity.Name);

            t.created_by = asp.Id;
            ts.Trips.Add(t);
            ts.SaveChanges();
            TripGroupContext t_gc = new TripGroupContext();
            TripGroup        tg   = new TripGroup();

            tg.Id        = t.id;
            tg.People    = User.Identity.Name;
            tg.TripAdmin = t.carAvailable;
            t_gc.TripGroups.Add(tg);
            t_gc.SaveChanges();

            //if similar trip exists send mail to those people
            List <Trip> similarTrips = new List <Trip>();

            similarTrips = ts.Trips.Where(s => s.source == t.source && s.destination == t.destination).ToList();
            foreach (var s in similarTrips)
            {
                AspNetUsers aspnetusers = us.AspNetUsers.Single(u => u.Id == s.created_by);
                if (aspnetusers.Email != User.Identity.Name)
                {
                    TripController tp = new TripController();
                    tp.SMTPSendEmail(aspnetusers.Email,
                                     User.Identity.Name + " has created a new trip similar to yours",
                                     "A trip similar to yours has been created on CarpoolManagementSystem");
                }
            }

            return(RedirectToAction("TripDetails/" + t.id, "Trip"));
        }