public JsonResult OylamamiGetir(Guid oylamaId)
        {
            VotedressUser user = new VotedressUser();

            user = Session["login"] as VotedressUser;


            OylamaManager oylamaManager = new OylamaManager();
            Vote_sade     vote_Sade     = oylamaManager.OylamaGetir(oylamaId, user.id);


            return(Json(vote_Sade, JsonRequestBehavior.AllowGet));
        }
        public JsonResult Oyla(int id)
        {
            VotedressUser user = new VotedressUser();

            user = Session["login"] as VotedressUser;

            OylamaManager oylama_manager = new OylamaManager();

            bool sonuc = oylama_manager.Oyla(user, id);

            if (sonuc == true)
            {
                Vote_sade yeni_oylama = oylama_manager.OylamaGetirOylamakIcin(user.id);

                return(Json(new { YeniOylama = yeni_oylama, IsSuccess = true, Message = "Oylama Başarılı" }, JsonRequestBehavior.AllowGet));
            }


            return(Json(new { IsSuccess = false, Message = "Oylama Başarısız" }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Index()
        {
            VotedressUser user = new VotedressUser();

            user = Session["login"] as VotedressUser;

            OylamaManager vote_manager = new OylamaManager();
            Vote_sade     oylama       = vote_manager.OylamaGetirOylamakIcin(user.id);

            if (oylama != null)
            {
                InVoteChatManager invoteChatManager = new InVoteChatManager();
                if (invoteChatManager.Chattemiyim(user.id, oylama.id) == null)
                {
                    VotedressUserDetailManager userdetail_Manager = new VotedressUserDetailManager();
                    UserDetail kullanici_detayi = new UserDetail();
                    kullanici_detayi = userdetail_Manager.GetUserDetail(user.id);
                    VotedressUser_sade sade_kullanici = new VotedressUser_sade()
                    {
                        id           = kullanici_detayi.UserId,
                        SocialId     = kullanici_detayi.User.SocialId,
                        SocialName   = kullanici_detayi.User.SocialName,
                        Name         = kullanici_detayi.Name,
                        SurName      = kullanici_detayi.SurName,
                        Birthday     = kullanici_detayi.Birthday,
                        Email        = kullanici_detayi.User.Email,
                        ProfileImage = kullanici_detayi.User.ProfileImage,
                        Sex          = kullanici_detayi.Sex,
                    };
                    InVoteChatManager repo_invotechatManager = new InVoteChatManager();
                    repo_invotechatManager.AddUserChat(user.id, oylama.id);
                }
            }
            else
            {
                return(View(oylama));//Oylama yok sayfasına yönlerdircen
            }
            return(View(oylama));
        }
        public OylamalarimViewModel OylamalarimSayfasi(Guid kullanici_id)
        {
            List <Vote> oylama = OylamalarimiGetir(kullanici_id);

            if (oylama.Count != 0)
            {
                DateTime enBuyukTarih = oylama.Max(x => x.StartTime);
                Vote     vote         = oylama.Where(x => x.StartTime == enBuyukTarih).FirstOrDefault();


                if (oylama.Count != 0)
                {
                    Vote_sade vote_sade = new Vote_sade();

                    vote_sade.id = vote.id;
                    vote_sade.PaylasimaAcikmi  = vote.PaylasimaAcikmi;
                    vote_sade.ProfilGorunsunMu = vote.ProfilGorunsunMu;
                    vote_sade.StartTime        = vote.StartTime;
                    vote_sade.TypeOfVote       = vote.TypeOfVote;
                    vote_sade.VoteLink         = vote.VoteLink;
                    vote_sade.FinishTime       = vote.FinishTime;


                    vote_sade.OylamaUrunleri = vote.VoteProduct.Select(x => new VoteProduct_sade()
                    {
                        id               = x.id,
                        ProductId        = x.Product.id,
                        ProductName      = x.Product.ProductName,
                        ProductImage     = x.Product.ProductImage,
                        Price            = x.Product.Price,
                        IsForSale        = x.Product.IsForSale,
                        VoteCount        = x.VoteCount,
                        LongDescription  = x.Product.LongDescription,
                        ShortDescription = x.Product.ShortDescription,
                        UrunSahibi       = new Magazalar_sade()
                        {
                            MagazaGuid          = x.Product.User.id,
                            SirketAdi           = x.Product.User.UserDetail.CompanyName,
                            SirketResmi         = x.Product.User.ProfileImage,
                            TelNo               = x.Product.User.UserDetail.PhoneNumber,
                            Email               = x.Product.User.Email,
                            WebSite             = "www.deneme.com",
                            MagazadakilerSayisi = x.Product.User.OnlineCount,
                            Sehir               = x.Product.User.UserDetail.City.CityName,
                            Ilce          = x.Product.User.UserDetail.County.CountyName,
                            Mahalle       = x.Product.User.UserDetail.Neighborhood.NeighborhoodName,
                            Adres         = x.Product.User.UserDetail.AdressDetail,
                            FranchiseAdi  = x.Product.User.Franchise.FranchiseName,
                            FranchiseLogo = x.Product.User.Franchise.FranchiseLogo,
                        },

                        OylamaResimleri = x.VoteImages.Select(t => new VoteImage_sade()
                        {
                            id        = t.id,
                            Aciklama  = t.Aciklama,
                            ImageNo   = t.ImageNo,
                            ImagePath = t.ImagePath
                        }).ToList()
                    }).ToList();

                    vote_sade.OylamaSahibi.id           = vote.User.id;
                    vote_sade.OylamaSahibi.Name         = vote.User.UserDetail.Name;
                    vote_sade.OylamaSahibi.SurName      = vote.User.UserDetail.SurName;
                    vote_sade.OylamaSahibi.Email        = vote.User.Email;
                    vote_sade.OylamaSahibi.Birthday     = vote.User.UserDetail.Birthday;
                    vote_sade.OylamaSahibi.Sex          = vote.User.UserDetail.Sex;
                    vote_sade.OylamaSahibi.ProfileImage = vote.User.ProfileImage;
                    vote_sade.OylamaSahibi.SocialId     = vote.User.SocialId;
                    vote_sade.OylamaSahibi.SocialName   = vote.User.SocialName;



                    if (vote.VoteMessage != null)
                    {
                        VoteMessage_sade voteMessage_sade;
                        for (int i = 0; i < vote.VoteMessage.Count; i++)
                        {
                            voteMessage_sade = new VoteMessage_sade();

                            voteMessage_sade.id             = vote.VoteMessage[i].id;
                            voteMessage_sade.Message        = vote.VoteMessage[i].Message;
                            voteMessage_sade.GondermeTarihi = vote.VoteMessage[i].GondermeTarihi;

                            voteMessage_sade.MesajSahibi.id           = vote.VoteMessage[i].User.id;
                            voteMessage_sade.MesajSahibi.Name         = vote.VoteMessage[i].User.UserDetail.Name;
                            voteMessage_sade.MesajSahibi.ProfileImage = vote.VoteMessage[i].User.ProfileImage;
                            voteMessage_sade.MesajSahibi.Sex          = vote.VoteMessage[i].User.UserDetail.Sex;
                            voteMessage_sade.MesajSahibi.SocialId     = vote.VoteMessage[i].User.SocialId;
                            voteMessage_sade.MesajSahibi.SocialName   = vote.VoteMessage[i].User.SocialName;
                            voteMessage_sade.MesajSahibi.SurName      = vote.VoteMessage[i].User.UserDetail.SurName;
                            voteMessage_sade.MesajSahibi.Email        = vote.VoteMessage[i].User.Email;
                            voteMessage_sade.MesajSahibi.Birthday     = vote.VoteMessage[i].User.UserDetail.Birthday;

                            vote_sade.OylamaMesajlari.Add(voteMessage_sade);
                        }
                    }

                    InVoteChatManager invotechatManager = new InVoteChatManager();
                    vote_sade.Chattekiler   = invotechatManager.ChattekileriGetir(vote.id);
                    vote_sade.SessionUserId = kullanici_id;

                    OylamalarimViewModel oylamalarimViewModel = new OylamalarimViewModel();
                    oylamalarimViewModel.vote_Sade         = vote_sade;
                    oylamalarimViewModel.oylamalarimModels = oylama.OrderByDescending(x => x.StartTime).Select(x => new OylamalarimModel()
                    {
                        OylamaId = x.id,
                        OylamaBaslangicZamani = x.StartTime,
                        OylamaBitisZamani     = x.FinishTime,
                        OylamaDurumu          = x.FinishTime < DateTime.Now ? true : false
                    }).ToList();

                    return(oylamalarimViewModel);
                }
            }
            return(null);
        }
        public Vote_sade OylamaGetirOylamakIcin(Guid kullanici_id)
        {
            List <Vote> oylamalar     = unitOfWork.Repository <Vote>().List();
            List <Guid> oyverdiklerim = unitOfWork.Repository <MyVoted>().List(x => x.User.id == kullanici_id).Select(x => x.Vote.id).ToList();

            DateTime    tarih  = DateTime.Now;
            List <Vote> oylama = (from p in oylamalar where !oyverdiklerim.Contains(p.id) && p.FinishTime >= tarih && p.User.id != kullanici_id && p.TypeOfVote == "genel" select p).ToList();


            if (oylama.Count != 0)
            {
                int en_kucuk = oylama.Min(x => x.Counter);

                Vote oylama2 = oylama.Where(x => x.Counter == en_kucuk).FirstOrDefault();

                oylama2.Counter = oylama2.Counter + 1;

                unitOfWork.Repository <Vote>().Update(oylama2);
                unitOfWork.SaveChanges();

                Vote_sade vote_sade = new Vote_sade();

                vote_sade.id = oylama2.id;
                vote_sade.PaylasimaAcikmi  = oylama2.PaylasimaAcikmi;
                vote_sade.ProfilGorunsunMu = oylama2.ProfilGorunsunMu;
                vote_sade.StartTime        = oylama2.StartTime;
                vote_sade.TypeOfVote       = oylama2.TypeOfVote;
                vote_sade.VoteLink         = oylama2.VoteLink;
                vote_sade.FinishTime       = oylama2.FinishTime;


                vote_sade.OylamaUrunleri = oylama2.VoteProduct.Select(x => new VoteProduct_sade()
                {
                    id               = x.id,
                    ProductId        = x.Product.id,
                    ProductName      = x.Product.ProductName,
                    ProductImage     = x.Product.ProductImage,
                    Price            = x.Product.Price,
                    IsForSale        = x.Product.IsForSale,
                    VoteCount        = x.VoteCount,
                    LongDescription  = x.Product.LongDescription,
                    ShortDescription = x.Product.ShortDescription,
                    UrunSahibi       = new Magazalar_sade()
                    {
                        MagazaGuid          = x.Product.User.id,
                        SirketAdi           = x.Product.User.UserDetail.CompanyName,
                        SirketResmi         = x.Product.User.ProfileImage,
                        TelNo               = x.Product.User.UserDetail.PhoneNumber,
                        Email               = x.Product.User.Email,
                        WebSite             = "www.deneme.com",
                        MagazadakilerSayisi = x.Product.User.OnlineCount,
                        Sehir               = x.Product.User.UserDetail.City.CityName,
                        Ilce          = x.Product.User.UserDetail.County.CountyName,
                        Mahalle       = x.Product.User.UserDetail.Neighborhood.NeighborhoodName,
                        Adres         = x.Product.User.UserDetail.AdressDetail,
                        FranchiseAdi  = x.Product.User.Franchise.FranchiseName,
                        FranchiseLogo = x.Product.User.Franchise.FranchiseLogo,
                    },

                    OylamaResimleri = x.VoteImages.Select(t => new VoteImage_sade()
                    {
                        id        = t.id,
                        Aciklama  = t.Aciklama,
                        ImageNo   = t.ImageNo,
                        ImagePath = t.ImagePath
                    }).ToList()
                }).ToList();

                vote_sade.OylamaSahibi.id           = oylama2.User.id;
                vote_sade.OylamaSahibi.Name         = oylama2.User.UserDetail.Name;
                vote_sade.OylamaSahibi.SurName      = oylama2.User.UserDetail.SurName;
                vote_sade.OylamaSahibi.Email        = oylama2.User.Email;
                vote_sade.OylamaSahibi.Birthday     = oylama2.User.UserDetail.Birthday;
                vote_sade.OylamaSahibi.Sex          = oylama2.User.UserDetail.Sex;
                vote_sade.OylamaSahibi.ProfileImage = oylama2.User.ProfileImage;
                vote_sade.OylamaSahibi.SocialId     = oylama2.User.SocialId;
                vote_sade.OylamaSahibi.SocialName   = oylama2.User.SocialName;



                if (oylama2.VoteMessage != null)
                {
                    VoteMessage_sade voteMessage_sade;
                    for (int i = 0; i < oylama2.VoteMessage.Count; i++)
                    {
                        voteMessage_sade = new VoteMessage_sade();

                        voteMessage_sade.id             = oylama2.VoteMessage[i].id;
                        voteMessage_sade.Message        = oylama2.VoteMessage[i].Message;
                        voteMessage_sade.GondermeTarihi = oylama2.VoteMessage[i].GondermeTarihi;

                        voteMessage_sade.MesajSahibi.id           = oylama2.VoteMessage[i].User.id;
                        voteMessage_sade.MesajSahibi.Name         = oylama2.VoteMessage[i].User.UserDetail.Name;
                        voteMessage_sade.MesajSahibi.ProfileImage = oylama2.VoteMessage[i].User.ProfileImage;
                        voteMessage_sade.MesajSahibi.Sex          = oylama2.VoteMessage[i].User.UserDetail.Sex;
                        voteMessage_sade.MesajSahibi.SocialId     = oylama2.VoteMessage[i].User.SocialId;
                        voteMessage_sade.MesajSahibi.SocialName   = oylama2.VoteMessage[i].User.SocialName;
                        voteMessage_sade.MesajSahibi.SurName      = oylama2.VoteMessage[i].User.UserDetail.SurName;
                        voteMessage_sade.MesajSahibi.Email        = oylama2.VoteMessage[i].User.Email;
                        voteMessage_sade.MesajSahibi.Birthday     = oylama2.VoteMessage[i].User.UserDetail.Birthday;

                        vote_sade.OylamaMesajlari.Add(voteMessage_sade);
                    }
                }

                InVoteChatManager invotechatManager = new InVoteChatManager();
                vote_sade.Chattekiler = invotechatManager.ChattekileriGetir(oylama2.id);



                vote_sade.SessionUserId = kullanici_id;
                return(vote_sade);
            }

            return(null);
        }
        public Vote_sade OylamaGetir(Guid oylamaId, Guid userId)
        {
            Vote vote = unitOfWork.Repository <Vote>().Find(x => x.id == oylamaId);


            if (vote.User.id == userId)
            {
                Vote_sade vote_sade = new Vote_sade();

                vote_sade.id = vote.id;
                vote_sade.PaylasimaAcikmi  = vote.PaylasimaAcikmi;
                vote_sade.ProfilGorunsunMu = vote.ProfilGorunsunMu;
                vote_sade.StartTime        = vote.StartTime;
                vote_sade.TypeOfVote       = vote.TypeOfVote;
                vote_sade.VoteLink         = vote.VoteLink;
                vote_sade.FinishTime       = vote.FinishTime;


                vote_sade.OylamaUrunleri = vote.VoteProduct.Select(x => new VoteProduct_sade()
                {
                    id               = x.id,
                    ProductId        = x.Product.id,
                    ProductName      = x.Product.ProductName,
                    ProductImage     = x.Product.ProductImage,
                    Price            = x.Product.Price,
                    IsForSale        = x.Product.IsForSale,
                    VoteCount        = x.VoteCount,
                    LongDescription  = x.Product.LongDescription,
                    ShortDescription = x.Product.ShortDescription,
                    UrunSahibi       = new Magazalar_sade()
                    {
                        MagazaGuid          = x.Product.User.id,
                        SirketAdi           = x.Product.User.UserDetail.CompanyName,
                        SirketResmi         = x.Product.User.ProfileImage,
                        TelNo               = x.Product.User.UserDetail.PhoneNumber,
                        Email               = x.Product.User.Email,
                        WebSite             = "www.deneme.com",
                        MagazadakilerSayisi = x.Product.User.OnlineCount,
                        Sehir               = x.Product.User.UserDetail.City.CityName,
                        Ilce          = x.Product.User.UserDetail.County.CountyName,
                        Mahalle       = x.Product.User.UserDetail.Neighborhood.NeighborhoodName,
                        Adres         = x.Product.User.UserDetail.AdressDetail,
                        FranchiseAdi  = x.Product.User.Franchise.FranchiseName,
                        FranchiseLogo = x.Product.User.Franchise.FranchiseLogo,
                    },

                    OylamaResimleri = x.VoteImages.Select(t => new VoteImage_sade()
                    {
                        id        = t.id,
                        Aciklama  = t.Aciklama,
                        ImageNo   = t.ImageNo,
                        ImagePath = t.ImagePath
                    }).ToList()
                }).ToList();

                vote_sade.OylamaSahibi.id           = vote.User.id;
                vote_sade.OylamaSahibi.Name         = vote.User.UserDetail.Name;
                vote_sade.OylamaSahibi.SurName      = vote.User.UserDetail.SurName;
                vote_sade.OylamaSahibi.Email        = vote.User.Email;
                vote_sade.OylamaSahibi.Birthday     = vote.User.UserDetail.Birthday;
                vote_sade.OylamaSahibi.Sex          = vote.User.UserDetail.Sex;
                vote_sade.OylamaSahibi.ProfileImage = vote.User.ProfileImage;
                vote_sade.OylamaSahibi.SocialId     = vote.User.SocialId;
                vote_sade.OylamaSahibi.SocialName   = vote.User.SocialName;



                if (vote.VoteMessage != null)
                {
                    VoteMessage_sade voteMessage_sade;
                    for (int i = 0; i < vote.VoteMessage.Count; i++)
                    {
                        voteMessage_sade = new VoteMessage_sade();

                        voteMessage_sade.id             = vote.VoteMessage[i].id;
                        voteMessage_sade.Message        = vote.VoteMessage[i].Message;
                        voteMessage_sade.GondermeTarihi = vote.VoteMessage[i].GondermeTarihi;

                        voteMessage_sade.MesajSahibi.id           = vote.VoteMessage[i].User.id;
                        voteMessage_sade.MesajSahibi.Name         = vote.VoteMessage[i].User.UserDetail.Name;
                        voteMessage_sade.MesajSahibi.ProfileImage = vote.VoteMessage[i].User.ProfileImage;
                        voteMessage_sade.MesajSahibi.Sex          = vote.VoteMessage[i].User.UserDetail.Sex;
                        voteMessage_sade.MesajSahibi.SocialId     = vote.VoteMessage[i].User.SocialId;
                        voteMessage_sade.MesajSahibi.SocialName   = vote.VoteMessage[i].User.SocialName;
                        voteMessage_sade.MesajSahibi.SurName      = vote.VoteMessage[i].User.UserDetail.SurName;
                        voteMessage_sade.MesajSahibi.Email        = vote.VoteMessage[i].User.Email;
                        voteMessage_sade.MesajSahibi.Birthday     = vote.VoteMessage[i].User.UserDetail.Birthday;

                        vote_sade.OylamaMesajlari.Add(voteMessage_sade);
                    }
                }

                InVoteChatManager invotechatManager = new InVoteChatManager();
                vote_sade.Chattekiler   = invotechatManager.ChattekileriGetir(vote.id);
                vote_sade.SessionUserId = userId;

                return(vote_sade);
            }

            return(null);
        }