Exemplo n.º 1
0
        public ActionResult Edit(OrderViewModel model)
        {
            Orders view = db.Orders.Find(model.OrderID);

            view.OrderDate      = model.OrderDate;
            view.RequiredDate   = model.RequiredDate;
            view.ShippedDate    = model.ShippedDate;
            view.ShipVia        = model.ShipVia;
            view.Freight        = model.Freight;
            view.ShipName       = model.ShipName;
            view.ShipAddress    = model.ShipAddress;
            view.ShipCity       = model.ShipCity;
            view.ShipRegion     = model.ShipRegion;
            view.ShipPostalCode = model.ShipPostalCode;
            view.ShipCountry    = model.ShipCountry;

            view.EmployeeID = model.EmployeeID;
            //view.LastName = model.Employees?.LastName;

            view.CustomerID = model.CustomerID;
            //view.CompanyName = model.Customers?.CompanyName;

            ViewBag.CompanyName = new SelectList((from c in db.Customers select new { CustomerID = c.CustomerID, CompanyName = c.CompanyName }), "CustomerID", "CompanyName", null);
            ViewBag.LastName    = new SelectList((from e in db.Employees select new { EmployeeID = e.EmployeeID, LastName = e.LastName }), "EmployeeID", "LastName", null);
            ViewBag.ShipVia     = new SelectList((from o in db.Orders select new { OrderID = o.OrderID, ShipVia = o.ShipVia }), "OrderID ", "ShipVia", null);

            db.SaveChanges();
            return(View("Index"));
        }//edit
Exemplo n.º 2
0
        public ActionResult Create([Bind(Include = "SupplierID,CompanyName,ContactName,ContactTitle,Address,City,Region,PostalCode,Country,Phone,Fax,HomePage")] Suppliers suppliers)
        {
            if (ModelState.IsValid)
            {
                db.Suppliers.Add(suppliers);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(suppliers));
        }
Exemplo n.º 3
0
        public ActionResult Create([Bind(Include = "CategoryID,CategoryName,Description,Picture")] Categories categories)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Add(categories);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(categories));
        }
Exemplo n.º 4
0
        public ActionResult Create([Bind(Include = "LoginID,UserName,PassWord,LoginErrorMessage")] Login login)
        {
            if (ModelState.IsValid)
            {
                db.Login.Add(login);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(login));
        }
Exemplo n.º 5
0
        public ActionResult Create([Bind(Include = "ShipperID,CompanyName,Phone")] Shippers shippers)
        {
            if (ModelState.IsValid)
            {
                db.Shippers.Add(shippers);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(shippers));
        }
Exemplo n.º 6
0
        public ActionResult Create([Bind(Include = "TerritoryID,TerritoryDescription,RegionID")] Territories territories)
        {
            if (ModelState.IsValid)
            {
                db.Territories.Add(territories);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.RegionID = new SelectList(db.Region, "RegionID", "RegionDescription", territories.RegionID);
            return(View(territories));
        }
Exemplo n.º 7
0
        public ActionResult Create([Bind(Include = "OrderID,ProductID,UnitPrice,Quantity,Discount")] Order_Details order_Details)
        {
            if (ModelState.IsValid)
            {
                db.Order_Details.Add(order_Details);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.OrderID   = new SelectList(db.Orders, "OrderID", "CustomerID", order_Details.OrderID);
            ViewBag.ProductID = new SelectList(db.Products, "ProductID", "ProductName", order_Details.ProductID);
            return(View(order_Details));
        }
Exemplo n.º 8
0
        public ActionResult Create([Bind(Include = "ProductID,ProductName,SupplierID,CategoryID,QuantityPerUnit,UnitPrice,UnitsInStock,UnitsOnOrder,ReorderLevel,Discontinued")] Products products)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(products);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "CategoryName", products.CategoryID);
            ViewBag.SupplierID = new SelectList(db.Suppliers, "SupplierID", "CompanyName", products.SupplierID);
            return(View(products));
        }
Exemplo n.º 9
0
        public ActionResult Create(CustomerViewModel model)
        {
            NorthwindDataEntities db = new NorthwindDataEntities();

            Customers view = new Customers();

            view.CustomerID   = model.CustomerID;
            view.CompanyName  = model.CompanyName;
            view.ContactName  = model.ContactName;
            view.ContactTitle = model.ContactTitle;
            view.Address      = model.Address;
            view.City         = model.City;
            view.Region       = model.Region;
            view.PostalCode   = model.PostalCode;
            view.Country      = model.Country;
            view.Phone        = model.Phone;
            view.Fax          = model.Fax;
            db.Customers.Add(view);

            //ViewBag.ReportsTo = new SelectList((from e in db.Employees select new { EmployeeID = e.EmployeeID, ReportsTo = e.ReportsTo }), "EmployeeID", "ReportsTo", null);

            try
            {
                db.SaveChanges();
            }

            catch (Exception ex)
            {
            }

            return(RedirectToAction("Index"));
        }//create
Exemplo n.º 10
0
        public ActionResult Update(Customers cust)
        {
            NorthwindDataEntities entities = new NorthwindDataEntities();
            string id = cust.CustomerID;

            bool OK = false;

            // onko kyseessä muokkaus vai uuden lisääminen?
            if (id == "(uusi)")
            {
                // kyseessä on uuden asiakkaan lisääminen, kopioidaan kentät
                Customers dbItem = new Customers()
                {
                    CustomerID  = cust.CompanyName.Substring(0, 5).Trim().ToUpper(), //luodaan CustomerID CompanyNamen 5:stä ensimmäisesta kirjaimesta isoilla kirjaimilla
                    CompanyName = cust.CompanyName,
                    Address     = cust.Address,
                    City        = cust.City
                };

                // tallennus tietokantaan
                entities.Customers.Add(dbItem);
                entities.SaveChanges();
                OK = true;
            }
            else
            {
                // muokkaus, haetaan id:n perusteella riviä tietokannasta
                Customers dbItem = (from c in entities.Customers
                                    where c.CustomerID == id
                                    select c).FirstOrDefault();
                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, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 11
0
        public ActionResult Edit(EmployeesViewModel model)
        {
            Employees view = db.Employees.Find(model.EmployeeID);

            view.LastName        = model.LastName;
            view.FirstName       = model.FirstName;
            view.Title           = model.Title;
            view.TitleOfCourtesy = model.TitleOfCourtesy;
            view.BirthDate       = model.BirthDate;
            view.HireDate        = model.HireDate;
            view.Address         = model.Address;
            view.City            = model.City;
            view.Region          = model.Region;
            view.PostalCode      = model.PostalCode;
            view.Country         = model.Country;
            view.HomePhone       = model.HomePhone;
            view.Extension       = model.Extension;
            //view.Photo = model.Photo;
            view.Notes     = model.Notes;
            view.ReportsTo = model.ReportsTo;
            //view.PhotoPath = model.PhotoPath;

            //if (cus.PinCodes == null)
            //{
            //    PinCodes pic = new PinCodes();
            //    pic.PinCode = model.PinCode;
            //    //usr.Password = "******";
            //    pic.Customers = cus;

            //    db.PinCodes.Add(pic);
            //}
            //else
            //{
            //    PinCodes pic = cus.PinCodes.FirstOrDefault();
            //    if (pic != null)
            //    {
            //        pic.PinCode = model.PinCode;
            //    }
            //}

            ViewBag.ReportsTo = new SelectList((from e in db.Employees select new { EmployeeID = e.EmployeeID, ReportsTo = e.ReportsTo }), "EmployeeID", "ReportsTo", null);

            db.SaveChanges();
            return(View("Index"));
        }//edit
Exemplo n.º 12
0
        public ActionResult Edit(CustomerViewModel model)
        {
            Customers view = db.Customers.Find(model.CustomerID);

            view.CustomerID   = model.CustomerID;
            view.CompanyName  = model.CompanyName;
            view.ContactName  = model.ContactName;
            view.ContactTitle = model.ContactTitle;
            view.Address      = model.Address;
            view.City         = model.City;
            view.Region       = model.Region;
            view.PostalCode   = model.PostalCode;
            view.Country      = model.Country;
            view.Phone        = model.Phone;
            view.Fax          = model.Fax;

            db.SaveChanges();

            return(View("Index"));
        }//edit
Exemplo n.º 13
0
        public ActionResult Create(OrderViewModel model)
        {
            NorthwindDataEntities db = new NorthwindDataEntities();

            Orders view = new Orders();

            view.OrderDate      = model.OrderDate;
            view.RequiredDate   = model.RequiredDate;
            view.ShippedDate    = model.ShippedDate;
            view.ShipVia        = model.ShipVia;
            view.Freight        = model.Freight;
            view.ShipName       = model.ShipName;
            view.ShipAddress    = model.ShipAddress;
            view.ShipCity       = model.ShipCity;
            view.ShipRegion     = model.ShipRegion;
            view.ShipPostalCode = model.ShipPostalCode;
            view.ShipCountry    = model.ShipCountry;

            view.EmployeeID = model.EmployeeID;
            //view.LastName = model.Employees?.LastName;

            view.CustomerID = model.CustomerID;
            //view.CompanyName = model.Customers?.CompanyName;

            ViewBag.CompanyName = new SelectList((from c in db.Customers select new { CustomerID = c.CustomerID, CompanyName = c.CompanyName }), "CustomerID", "CompanyName", null);
            ViewBag.LastName    = new SelectList((from e in db.Employees select new { EmployeeID = e.EmployeeID, LastName = e.LastName }), "EmployeeID", "LastName", null);
            ViewBag.ShipVia     = new SelectList((from o in db.Orders select new { OrderID = o.OrderID, ShipVia = o.ShipVia }), "OrderID ", "ShipVia", null);

            db.Orders.Add(view);

            try
            {
                db.SaveChanges();
            }

            catch (Exception ex)
            {
            }

            return(RedirectToAction("Index"));
        }//create
Exemplo n.º 14
0
        public ActionResult DeleteCustomer(string id)
        {
            NorthwindDataEntities entities = new NorthwindDataEntities();

            // 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));
        }
Exemplo n.º 15
0
        public ActionResult Create(EmployeesViewModel model)
        {
            NorthwindDataEntities db = new NorthwindDataEntities();

            Employees view = new Employees();

            view.LastName        = model.LastName;
            view.FirstName       = model.FirstName;
            view.Title           = model.Title;
            view.TitleOfCourtesy = model.TitleOfCourtesy;
            view.BirthDate       = model.BirthDate;
            view.HireDate        = model.HireDate;
            view.Address         = model.Address;
            view.City            = model.City;
            view.Region          = model.Region;
            view.PostalCode      = model.PostalCode;
            view.Country         = model.Country;
            view.HomePhone       = model.HomePhone;
            view.Extension       = model.Extension;
            //view.Photo = model.Photo;
            view.Notes     = model.Notes;
            view.ReportsTo = model.ReportsTo;
            //view.PhotoPath = model.PhotoPath;

            ViewBag.ReportsTo = new SelectList((from e in db.Employees select new { EmployeeID = e.EmployeeID, ReportsTo = e.ReportsTo }), "EmployeeID", "ReportsTo", null);

            db.Employees.Add(view);

            try
            {
                db.SaveChanges();
            }

            catch (Exception ex)
            {
            }

            return(RedirectToAction("Index"));
        }//create