示例#1
0
        public ActionResult Conversation(int Rid)
        {
            BarterBot2.Models.User r = db.users.Single(d => d.UserID == Rid);
            HomeController.data3.Add(r.FirstName);

            int sender = Convert.ToInt32(Session["UserId"]);

            Conversation c1 = new Models.Conversation();

            c1.SenderID   = sender;
            c1.ReceiverID = Rid;
            string SR  = sender.ToString() + Rid.ToString();
            string SR2 = Rid.ToString() + sender.ToString();

            reverseId   = Convert.ToInt32(SR2);
            c1.SenRevID = Convert.ToInt32(SR);
            c           = c1;

            return(RedirectToAction("create"));
        }
示例#2
0
        //LoggedIn

        public ActionResult LoggedIn()
        {
            OfferedServices.Clear();

            //MessagesController d = new MessagesController();

            BarterBot2DbContext db = new BarterBot2DbContext();

            List <Service>  services  = new List <Service>();
            List <Interest> interests = new List <Interest>();
            List <Request>  requests  = new List <Request>();

            if (Session["UserId"] != null)
            {
                foreach (Service s in db.Services)
                {
                    if (s.UserID == Convert.ToInt32(Session["UserId"]))
                    {
                        services.Add(s);
                    }
                }

                foreach (Interest i in db.interests)
                {
                    if (i.UserID == Convert.ToInt32(Session["UserId"]))
                    {
                        interests.Add(i);
                    }
                }



                UserData ud = new UserData();
                ud.interests = interests.ToList();
                ud.services  = services.ToList();
                int ID = Convert.ToInt32(Session["UserId"]);


                BarterBot2.Models.User uuu = db.users.Single(s => s.UserID == ID);
                NAMEIP = uuu.FirstName;
                if (db.requests.Count() != 0)
                {
                    foreach (Service s in db.Services)
                    {
                        if (s.UserID != ID)
                        {
                            OfferedServices.Add(s);
                        }
                    }

                    foreach (Request r in db.requests)
                    {
                        foreach (Service s in OfferedServices.ToList())
                        {
                            if (r.SeekerUserID == ID && s.ServiceID == r.ProviderServiceID)
                            {
                                OfferedServices.Remove(s);
                            }
                        }
                    }
                }
                else
                {
                    foreach (Service s in db.Services)
                    {
                        if (s.UserID != Convert.ToInt32(Session["UserId"]))
                        {
                            OfferedServices.Add(s);
                        }
                    }
                }


                foreach (Request r in db.requests)
                {
                    if (r.ProviderUserID == Convert.ToInt32(Session["UserId"]) && r.Status == "sent")
                    {
                        ud.comingRequests.Add(r);
                    }
                }

                foreach (Request r in db.requests)
                {
                    if (r.SeekerUserID == Convert.ToInt32(Session["UserId"]))
                    {
                        ud.sentRequests.Add(r);
                    }
                }

                ud.offeredServices = OfferedServices.ToList();

                List <int>     conversationIDs = new List <int>();
                List <Message> Messages        = new List <Message>();


                foreach (Conversation g in db.conversations)
                {
                    if (g.SenderID == ID || g.ReceiverID == ID)
                    {
                        conversationIDs.Add(g.SenRevID);

                        string merge   = g.ReceiverID.ToString() + g.SenderID.ToString();
                        int    reverse = Convert.ToInt32(merge);

                        conversationIDs.Add(reverse);
                    }
                }

                foreach (Message m in db.messages)
                {
                    foreach (int Mid in conversationIDs)
                    {
                        if (m.SenRevID == Mid)
                        {
                            Messages.Add(m);
                        }
                    }
                }

                ud.messages        = Messages;
                ud.conversationIds = conversationIDs;
                ud.ID = ID;

                Session["LoginFlag"] = 1;
                return(View(ud));
            }

            else
            {
                Session["LoginFlag"] = null;
                return(RedirectToAction("Login"));
            }
        }