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 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 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);
        }