Exemplo n.º 1
0
        public override void InitSample(string connectionString)
        {
            if (context != null)
            {
                context.Dispose();
            }

            context = CreateContext(connectionString);
        }
Exemplo n.º 2
0
        public static bool AgregarUsuario(USERS persona, Security personaSecurity)
        {
            NorthwindEntities contexto = null;

            //NorthwindEntities contexto2 = null;

            try
            {
                contexto = new NorthwindEntities();

                contexto.sp_Proyecto_InsertarUsuario(persona.Identificacion, persona.Nombre, persona.Primer_Apellido, persona.Segundo_Apellido, persona.Fecha_nacimiento, persona.Telefono, persona.Correo, persona.Direccion, persona.CREATEDATE);
                contexto.sp_Proyecto_InsertarUsuarioSecurity(persona.Identificacion, personaSecurity.Nombre_Usuario, personaSecurity.clave, personaSecurity.TIPO_USUARIO, personaSecurity.Token);

                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (contexto != null)
                {
                    contexto.Dispose();
                }
            }
        }
Exemplo n.º 3
0
        public static bool AgregarPedido(Pedidos Pedidos)
        {
            NorthwindEntities contexto = null;

            try
            {
                contexto = new NorthwindEntities();

                contexto.Pedidos.Add(Pedidos);
                contexto.SaveChanges();

                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (contexto != null)
                {
                    contexto.Dispose();
                }
            }
        }
Exemplo n.º 4
0
 protected override void DisposeCore()
 {
     if (dbContext != null)
     {
         dbContext.Dispose();
     }
 }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            Customers customer = new Customers();

            customer.CustomerID   = "NIDE";
            customer.ContactName  = "niky";
            customer.Phone        = "0883";
            customer.Address      = "test";
            customer.City         = "test";
            customer.CompanyName  = "test";
            customer.ContactTitle = "test";
            customer.Country      = "test";
            customer.Fax          = "test";
            customer.Phone        = "test";
            customer.PostalCode   = "test";
            customer.Region       = "test";
            DAOClass.Insert(customer);

            NorthwindEntities database    = new NorthwindEntities();
            var customerToModifyAndDelete = (from p in database.Customers where p.CustomerID == "NIDE" select p).First();

            database.Dispose();

            customerToModifyAndDelete.ContactName = "Nikolay";
            customerToModifyAndDelete.Phone       = "088340";
            DAOClass.Modify(customerToModifyAndDelete.CustomerID, customerToModifyAndDelete);

            DAOClass.Delete(customerToModifyAndDelete.CustomerID);
        }
Exemplo n.º 6
0
        public static bool AgregarVenta(SALES venta)
        {
            NorthwindEntities contexto = null;

            try
            {
                contexto = new NorthwindEntities();

                contexto.SALES.Add(venta);
                contexto.SaveChanges();

                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (contexto != null)
                {
                    contexto.Dispose();
                }
            }
        }
Exemplo n.º 7
0
 public void Dispose()
 {
     if (isDisposed == false)
     {
         _dbContext?.Dispose();
         isDisposed = true;
     }
 }
Exemplo n.º 8
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         db.Dispose();
     }
     base.Dispose(disposing);
 }
Exemplo n.º 9
0
        public virtual void Reset()
        {
            if (entities != null)
            {
                entities.Dispose();
            }

            Initialize();
        }
Exemplo n.º 10
0
        public ActionResult Index2()
        {
            NorthwindEntities db    = new NorthwindEntities(); //Uusi ilmentymä tietokannasta nimellä db
            List <Products>   model = db.Products.ToList();    //Lista nimeltä model, joka ottaa vastaan Products kategoriaan kuuluvia rivejä, jotka sijoitetaan db oliosta listana.

            db.Dispose();                                      //Suljetaan tietokanta yhteys

            return(View(model));                               //Palautetaan näkymälle lista model.
        }
Exemplo n.º 11
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         _unitOfWork.Dispose();
         _context.Dispose();
     }
     base.Dispose(disposing);
 }
        public ActionResult Index2()
        {
            NorthwindEntities entities = new NorthwindEntities();

            List <Products> model = entities.Products.ToList();

            entities.Dispose();

            return(View(model));
        }
        public List <string> GetProducts()
        {
            List <string> products = null;

            DataCache dataCache = null;

            if (this.enableCache)
            {
                try
                {
                    dataCache = cacheFactory.GetDefaultCache();
                    products  = dataCache.Get("products") as List <string>;
                    if (products != null)
                    {
                        products[0] = "(from cache)";
                        return(products);
                    }
                }
                catch (DataCacheException ex)
                {
                    if (ex.ErrorCode != DataCacheErrorCode.RetryLater)
                    {
                        throw;
                    }

                    // ignore temporary failures
                }
            }

            NorthwindEntities context = new NorthwindEntities();

            try
            {
                var query = from product in context.Products
                            select product.ProductName;
                products = query.ToList();
            }
            finally
            {
                if (context != null)
                {
                    context.Dispose();
                }
            }

            products.Insert(0, "(from data source)");

            if (this.enableCache && dataCache != null)
            {
                dataCache.Add("products", products, TimeSpan.FromSeconds(30));
            }

            return(products);
        }
Exemplo n.º 14
0
        [Route("api/Values/OrderCount")] //reitin määritys
        public int OrderCount()
        {
            //tietokantayhteys alustaminen
            NorthwindEntities entities = new NorthwindEntities();
            //paikallinen muuttuja, joka laskee tilausten lkm:n Orders-taulusta
            int orderCount = entities.Orders.Count();

            //vapautetaan muisti, tietokantayhteyden sulkeminen
            entities.Dispose();
            //palautetaan tulos
            return(orderCount);
        }
Exemplo n.º 15
0
 protected virtual void Dispose(bool disposing)
 {
     if (!_disposed)
     {
         if (disposing)
         {
             if (_db != null)
             {
                 _db.Dispose();
             }
         }
         _disposed = true;
     }
 }
Exemplo n.º 16
0
        // GET: Customer
        public ActionResult Index()
        {
            ViewBag.OmaTieto = "ABC123";

            NorthwindEntities entities = new NorthwindEntities();
            //muodostetaan asiakastaulun tiedoista model-niminen lista ja pyydetään entities-oliosta Customers-entities-kokoelmasta
            //kokonaisuutena listaksi
            List <Customers> model = entities.Customers.ToList();

            entities.Dispose();

            //palautetaan näkymälle model-olio
            return(View(model));
        }
Exemplo n.º 17
0
        public ActionResult Update(Customers cust)
        {
            NorthwindEntities entities = new NorthwindEntities();
            string            id       = cust.CustomerID;

            bool OK = false;

            //onko kyseessä uusi lisäys vai vanhan muokkaus
            if (id == "(uusi)")
            {
                //uuden lisääminen eli kopioidaan kentät
                Customers dbItem = new Customers()
                {
                    //otetaan CompanyNamesta Substring funktiolla 5 ensimmäistä merkkiä, jos loppuu
                    //välilyöntiin tehdään Trim()
                    CustomerID  = cust.CompanyName.Substring(0, 5).Trim().ToUpper(),
                    CompanyName = cust.CompanyName,
                    Address     = cust.Address,
                    City        = cust.City
                };
                //tallennetaan uusi lisäys tietokantaan
                entities.Customers.Add(dbItem);
                entities.SaveChanges();
                OK = true;
            }
            else
            {
                //muokkaus eli haetaan id:n perusteella rivi tietokannasta
                Customers dbItem = (from c in entities.Customers
                                    where c.CustomerID == id
                                    select c).FirstOrDefault();
                //tallennetaan vain ne tiedot joita käyttäjä on voinut muokata
                if (dbItem != null)
                {
                    dbItem.CompanyName = cust.CompanyName;
                    dbItem.Address     = cust.Address;
                    dbItem.City        = cust.City;

                    //tallennus tietokantaan
                    entities.SaveChanges();
                    OK = true;
                }
            }
            entities.Dispose();
            return(Json(OK));
        }
        // GET: Products
        public ActionResult Index()
        {
            if (Session["UserName"] == null)  //näyttää NavBarissa (in) / (out) -tiedon, pitää lisätä jokaisen controllerin  indexiin, jos halutaan näkyvän niissä
            {
                ViewBag.LoggedStatus = "Out";
                return(RedirectToAction("login", "home")); //tämä vie ensin login-ruutuun
            }
            else
            {
                ViewBag.LoggedStatus = "In";

                NorthwindEntities entities = new NorthwindEntities();
                List <Products>   model    = entities.Products.ToList();
                entities.Dispose();
                return(View(model));
            }
        }
Exemplo n.º 19
0
        // GET: Sales
        public ActionResult Index()
        {
            NorthwindEntities entities = new NorthwindEntities();

            try
            {
                //muodostetaan lista asiakkaista
                List <Customers> model = entities.Customers.ToList();
                //palautetaan lista näkymänä
                return(View(model));
            }
            finally
            {
                //resurssien vapautus
                entities.Dispose();
            }
        }
Exemplo n.º 20
0
        public static void Main()
        {
            NorthwindEntities connection        = new NorthwindEntities();
            NorthwindEntities anotherConnection = new NorthwindEntities();

            Customer anton   = connection.Customers.Where(cust => cust.CustomerID == "ANTON").FirstOrDefault();
            Customer antonio = anotherConnection.Customers.Where(cust => cust.CustomerID == "ANTON").FirstOrDefault();


            anton.Region   = "BG";
            antonio.Region = "GR";

            connection.SaveChanges();
            anotherConnection.SaveChanges();

            connection.Dispose();
            anotherConnection.Dispose();
        }
Exemplo n.º 21
0
        public JsonResult GetList()
        {
            NorthwindEntities entities = new NorthwindEntities();
            // List<Customers> model = entities.Customers.ToList();

            //muodostetaan näkymäluokka, joka halutaan välittää Ajaxin kautta
            var model = (from c in entities.Customers
                         select new
            {
                CustomerID = c.CustomerID,
                CompanyName = c.CompanyName,
                Address = c.Address,
                City = c.City
            }).ToList();
            string json = JsonConvert.SerializeObject(model);

            entities.Dispose();

            return(Json(json, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 22
0
        [Route("api/Values/LastNOrders/{id:int}")] //reitin määritys
        public List <string> LastNOrders(int id)   //käytetään parametrina int, koska AppStart/WebApiConfigissa routeTemplate: "api/{controller}/{id}",
        {
            //tietokantayhteys alustaminen
            NorthwindEntities entities = new NorthwindEntities();
            //muuttujan alustus
            int numberOfOrdersToReturn = id;
            //lista-muuttuja, joka lajittelee tulokset tilauspäivän mukaan laskevasti
            //Orders -taulusta ja palauttaa niistä 5 Take-funktiolla

            List <Orders> lastOrders = (from o in entities.Orders
                                        orderby o.OrderDate descending
                                        select o).Take(numberOfOrdersToReturn).ToList();

            //pyydetään Orders-taulun tiedoista pelkästään CompanyName asiakastaulun kautta
            List <string> customerNames = lastOrders.Select(o => o.Customers.CompanyName).ToList();

            //vapautetaan muisti, tietokantayhteyden sulkeminen
            entities.Dispose();
            //palautetaan tulos
            return(customerNames);
        }
Exemplo n.º 23
0
        public ActionResult DeleteFromJQuery(string id)
        {
            NorthwindEntities db = new NorthwindEntities();
            int iid = int.Parse(id);
            // etsitään id:n perusteella asiakasrivi kannasta
            bool   OK     = false;
            Orders dbItem = (from o in db.Orders
                             where o.OrderID == iid
                             select o).FirstOrDefault();

            if (dbItem != null)
            {
                // tietokannasta poisto
                db.Orders.Remove(dbItem);
                db.SaveChanges();
                OK = true;
            }
            db.Dispose();

            return(Json(OK, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 24
0
        public ActionResult Delete(string id)
        {
            NorthwindEntities entities = new NorthwindEntities();

            // etsitään id:n perusteella asiakasrivi kannasta
            bool      OK     = false;
            Customers dbItem = (from c in entities.Customers
                                where c.CustomerID == id
                                select c).FirstOrDefault();

            if (dbItem != null)
            {
                // tietokannasta poisto
                entities.Customers.Remove(dbItem);
                entities.SaveChanges();
                OK = true;
            }
            entities.Dispose();

            return(Json(OK, JsonRequestBehavior.AllowGet));
        }
        public List <string> GetProducts()
        {
            List <string> products = null;

            NorthwindEntities context = new NorthwindEntities();

            try
            {
                var query = from product in context.Products
                            select product.ProductName;
                products = query.ToList();
            }
            finally
            {
                if (context != null)
                {
                    context.Dispose();
                }
            }

            return(products);
        }
Exemplo n.º 26
0
        public static void Main(string[] args)
        {
            var firstDbContext  = new NorthwindEntities();
            var secondDbContext = new NorthwindEntities();


            var randomRegion        = firstDbContext.Regions.FirstOrDefault();
            var anotherRandomRegion = secondDbContext.Regions.FirstOrDefault();

            randomRegion.RegionDescription        = "Changed Description 1";
            anotherRandomRegion.RegionDescription = "changed Description 2";

            firstDbContext.SaveChanges();
            secondDbContext.SaveChanges();

            firstDbContext.Dispose();
            secondDbContext.Dispose();


            var thirdDbContext = new NorthwindEntities();
            var actualRegion   = thirdDbContext.Regions.FirstOrDefault();

            Console.WriteLine(actualRegion.RegionDescription);
        }
Exemplo n.º 27
0
        private static void MakeConcurencyChanges()
        {
            //7. Try to open two different data contexts and perform concurrent changes
            //on the same records. What will happen at SaveChanges()? How to deal with it?

            NorthwindEntities dbContext1 = new NorthwindEntities();
            Employee          employee1  = dbContext1.Employees.Find(10);

            //employee1.City = "Burgas";
            dbContext1.Employees.Remove(employee1);

            //dbContext1.SaveChanges();

            NorthwindEntities dbContext2 = new NorthwindEntities();
            Employee          employee2  = dbContext2.Employees.Find(10);

            employee2.City = "Varna";

            dbContext1.SaveChanges();
            dbContext2.SaveChanges();

            dbContext1.Dispose();
            dbContext2.Dispose();
        }
Exemplo n.º 28
0
        public ActionResult GetOrderData(string id)
        {
            NorthwindEntities entities = new NorthwindEntities();

            try
            {
                List <Orders> orders = (from o in entities.Orders
                                        where o.CustomerID == id
                                        orderby o.OrderDate descending
                                        select o).ToList();
                StringBuilder html = new StringBuilder();
                html.AppendLine("<td colspan=\"5\">" +
                                "<table class=\"table table-striped\">");

                foreach (Orders order in orders)
                {
                    html.AppendLine("<tr><td>" +
                                    order.OrderDate.Value.ToShortDateString() + "</td>" +
                                    "<td>" + order.OrderID + "</td>" +
                                    "<td>" + order.ShipCity + "</td>" +
                                    "<td>" + order.RequiredDate.Value.ToShortDateString() + "</td></tr>");
                }


                html.AppendLine("</table></td>");


                var jsonData = new { html = html.ToString() };
                return(Json(jsonData, JsonRequestBehavior.AllowGet));
            }
            finally
            {
                //resurssien vapautus
                entities.Dispose();
            }
        }
Exemplo n.º 29
0
 public void Dispose()
 {
     context.Dispose();
 }
Exemplo n.º 30
0
 public void Dispose()
 {
     dc.Dispose();
 }