public List <advertisements> GetAdver(List <Advertisement> lst)
        {
            List <advertisements> adver = new List <advertisements>();

            lst.ToList().ForEach(a =>
            {
                // if (a.category == categoryId)
                // {
                advertisements ad = new advertisements()
                {
                    adKod    = a.adKod,
                    userKod  = (int)a.userKod,
                    category = (int)a.category,
                    date     = (DateTime)a.date,
                    area     = a.area,
                    color    = a.color,
                    shape    = a.shape,
                    material = a.material,
                    status   = (bool)a.status,
                    // categoryName = null
                    image = a.image
                };
                adver.Add(ad);
                // }
            });

            return(adver);
        }
 public void findUsersToGetNewAd(advertisements ad)
 {
     UsersForGetMail.ToList().ForEach(a =>
     {
         //userKod mean to category
         if (a.userKod == ad.category && ad.status == false)
         {
             ad.material = a.mail;
             ad.image    = a.firstName;
             sendMailWithNewAd(ad);
         }
     });
 }
        public void apdateAd(advertisements adv)
        {
            var query =
                from ad in db.Advertisement
                where ad.adKod == adv.adKod
                select ad;

            foreach (Advertisement ad in query)
            {
                ad.status   = adv.status;
                ad.category = adv.category;
            }
        }
        public string sendMailWithNewAd(advertisements ad)
        {
            mail email = new mail();

            try
            {
                var          fromAddress  = new MailAddress("*****@*****.**", "From Name");
                var          toAddress    = new MailAddress(ad.material, "To Name");
                const string fromPassword = "******";
                const string subject      = "מייל מאתר lost-found";
                var          catName      = db.Categories.ToList().Find(x => x.categoryKod == ad.category).categoryName;
                catName = catName.Replace(" ", "");

                string body = ad.image + " שלום! " + " באתרינו נוספה מודעה חדשה מקטגוריית " + catName + " באיזור " + ad.area;


                var smtp = new SmtpClient
                {
                    Host                  = "smtp.gmail.com",
                    Port                  = 587,
                    EnableSsl             = true,
                    DeliveryMethod        = SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Credentials           = new NetworkCredential(fromAddress.Address, fromPassword)
                };
                using (var message = new MailMessage(fromAddress, toAddress)
                {
                    Subject = subject,
                    Body = body
                })
                {
                    smtp.Send(message);
                }
                return("משתמש קיבל מודעה רלוונטית חדשה...");
            }


            catch (Exception ex)
            {
                return(ex.ToString());
            }
        }