public ActionResult AddArea(City city)
        {
            ModelState.Remove("AreaId");
            ModelState.Remove("Name");
            city.Name = "tempOption";
            if (ModelState.IsValid)
            {
                using (var ctx = new EFCodeFirstContext())
                {
                    var exist = ctx.Area.Where(s => s.Name == city.AreaName).FirstOrDefault();

                    if (exist != null)
                    {
                        return(Json("exist", JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        Area area = new Area()
                        {
                            Name      = city.AreaName,
                            CityRefId = city.CityId
                        };
                        ctx.Area.Add(area);
                        ctx.SaveChanges();
                        return(Json("success", JsonRequestBehavior.AllowGet));
                    }
                }
            }
            return(Json("error", JsonRequestBehavior.AllowGet));
        }
        public ActionResult AddRegister(Register register)
        {
            ModelState.Remove("RegisterId");
            if (ModelState.IsValid)
            {
                register.isAdmin = true;
                Register existRegister;
                using (var ctx = new EFCodeFirstContext())
                {
                    existRegister = ctx.Register.Where(s => s.Email == register.Email).FirstOrDefault <Register>();
                }

                if (existRegister == null)
                {
                    using (var context = new EFCodeFirstContext())
                    {
                        context.Register.Add(register);
                        context.SaveChanges();
                    }
                }
                else
                {
                    return(Json("exist", JsonRequestBehavior.AllowGet));
                }
                return(Json("success", JsonRequestBehavior.AllowGet));
            }
            return(Json("error", JsonRequestBehavior.AllowGet));
        }
        public ActionResult AddCity(City city)
        {
            ModelState.Remove("CityId");
            ModelState.Remove("AreaName");
            city.AreaName = "tempOption";
            if (ModelState.IsValid)
            {
                using (var ctx = new EFCodeFirstContext())
                {
                    var exist = ctx.City.Where(s => s.Name == city.Name).FirstOrDefault();

                    if (exist != null)
                    {
                        return(Json("exist", JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        try
                        {
                            ctx.City.Add(city);
                            ctx.SaveChanges();
                        }
                        catch (DbEntityValidationException e)
                        {
                            throw e;
                        }
                        var citiesList = new SelectList(ctx.City.ToList().Select(x => new { Value = x.CityId, Text = x.Name }), "Value", "Text");
                        return(Json(citiesList, JsonRequestBehavior.AllowGet));
                    }
                }
            }
            return(Json("error", JsonRequestBehavior.AllowGet));
        }
        public static int KullaniciKayitEkle(Kullanici K)
        {
            int Sonuc = 0;

            using (EFCodeFirstContext efc = new EFCodeFirstContext())
            {
                efc.Kullanicilar.Add(K);
                Sonuc = efc.SaveChanges();
            }
            return(Sonuc);
        }
        public static int KisiEkle(Kisi K)
        {
            int sonuc = 0;

            using (EFCodeFirstContext efc = new EFCodeFirstContext())
            {
                efc.Kisiler.Add(K);
                sonuc = efc.SaveChanges();
            }
            return(sonuc);
        }
        //Birden Fazla Kayıt Ekleme List - Generic
        public static int FirmaKayitlarEkle(List <Firma> FList)
        {
            int sonuc = 0;

            using (EFCodeFirstContext efc = new EFCodeFirstContext())
            {
                efc.Firmalar.AddRange(FList);
                sonuc = efc.SaveChanges();
            }
            return(sonuc);
        }
        public static int FirmaKayitEkle(Firma F)
        {
            int sonuc = 0;



            using (EFCodeFirstContext efc = new EFCodeFirstContext())
            {
                efc.Firmalar.Add(F);
                sonuc = efc.SaveChanges();
            }
            return(sonuc);
        }
Exemple #8
0
 internal void Create(BlogPost model)
 {
     try
     {
         using (var context = new EFCodeFirstContext())
         {
             context.BlogPosts.Add(model);
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
        public static void KisiGuncelle(string isim, string soyisim)
        {
            using (EFCodeFirstContext efc = new EFCodeFirstContext())
            {
                Kisi BulunanKisi = (from I in efc.Kisiler where I.Isim == "Emma" && I.Soyisim == "Buckley" select I).FirstOrDefault();
                if (BulunanKisi != null)
                {
                    BulunanKisi.Telefon = "65648949";
                    efc.SaveChanges();
                }

                //Kisi BulunanKisi1 = efc.Kisiler.Find(Guid.Parse("{4E3EF687-CDEB-475A-B9D6-45C4CB796EF1}"));
                // if(BulunanKisi1!=null)
                // {
                //     BulunanKisi1.Telefon = "36549466";
                //     efc.SaveChanges();
                // }
            }
        }
        public static void KisiSil(Guid id)
        {
            using (EFCodeFirstContext efc = new EFCodeFirstContext())
            {
                //LINQ ile :
                //Kisi Silinecek = (from I in efc.Kisiler where I.ID == id select I).FirstOrDefault();


                Kisi Silinecek = efc.Kisiler.Find(Guid.Parse($"{id}"));
                if (Silinecek != null)
                {
                    efc.Kisiler.Remove(Silinecek);
                    efc.SaveChanges();
                    Console.WriteLine($"{id} : Numaralı Kayıt Silindi ");
                }
                else
                {
                    Console.WriteLine("Kayıt Bulunamadı ...");
                }
            }
        }