示例#1
0
        public JsonResult SiparisOlustur(List <SiparisViewModel> model)
        {
            if (model == null)
            {
                return(Json("", JsonRequestBehavior.AllowGet));
            }
            NorthContext db = new NorthContext();

            using (var tran = db.Database.BeginTransaction())
            {
                try
                {
                    var siparis = new Order()
                    {
                        CustomerID   = "DUMON",
                        EmployeeID   = 1,
                        OrderDate    = DateTime.Now,
                        RequiredDate = DateTime.Now.AddDays(7),
                        ShipVia      = 1,
                        Freight      = 59,
                        ShipName     = "Lucky S",
                        ShipRegion   = "Çorum",
                        ShipCity     = "Sungurlu",
                        ShipCountry  = "USÇ"
                    };
                    db.Orders.Add(siparis);
                    db.SaveChanges();
                    foreach (var item in model)
                    {
                        db.Order_Details.Add(new Order_Detail
                        {
                            OrderID   = siparis.OrderID,
                            ProductID = item.ProductID,
                            Discount  = 0,
                            Quantity  = item.Count,
                            UnitPrice = item.UnitPrice
                        });
                    }
                    db.SaveChanges();
                    tran.Commit();
                    var msg = new
                    {
                        success = true,
                        message = $"{siparis.OrderID} nolu sipariş başarıyla oluşturuldu"
                    };
                    return(Json(msg, JsonRequestBehavior.AllowGet));
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    var msg = new
                    {
                        success = false,
                        message = "Sipariş oluşturulurken bir hata oluştu " + ex.Message
                    };
                    return(Json(msg, JsonRequestBehavior.AllowGet));
                }
            }
        }
 private void button1_Click(object sender, EventArgs e)
 {
     using (var context = new NorthContext())
     {
         var results = context.Customers.Include(item => item.ContactTitleNavigation).ToList();
         Console.WriteLine();
     }
 }
示例#3
0
 public static List <Category> Categories()
 {
     using (var context = new NorthContext())
     {
         return(context.Categories
                .OrderBy(category => category.CategoryName).ToList());
     }
 }
示例#4
0
 public static List <Product> Products()
 {
     using (var context = new NorthContext())
     {
         return(context.Products
                .OrderBy(product => product.ProductName).ToList());
     }
 }
示例#5
0
        public GenericRepository(NorthContext context)
        {
            if (context == null)
            {
                throw new ArgumentException("An instance of DbContext is required to use this repository.", "context");
            }

            this.Context = context;
            this.DbSet   = this.Context.Set <T>();
        }
示例#6
0
 public static List <CategoryItem> CategoryItems()
 {
     using (var context = new NorthContext())
     {
         return(context.Categories.Select(category => new CategoryItem()
         {
             CategoryId = category.CategoryId,
             CategoryName = category.CategoryName
         }).OrderBy(category => category.CategoryName).ToList());
     }
 }
示例#7
0
        public JsonResult UrunleriGetir()
        {
            NorthContext db    = new NorthContext();
            var          model = db.Products.Select(x => new
            {
                x.ProductID,
                x.ProductName,
                x.UnitPrice,
                x.Category.CategoryName,
                x.UnitsInStock,
                x.Discontinued,
                x.Supplier.CompanyName
            }).ToList();

            return(Json(model, JsonRequestBehavior.AllowGet));
        }
        private void Form1_Shown(object sender, EventArgs e)
        {
            listView1.View = View.Details;

            listView1.GridLines     = true;
            listView1.OwnerDraw     = false;
            listView1.FullRowSelect = true;

            //Add column header
            listView1.Columns.Add("NameColumn", 150);
            listView1.Columns.Add("VersionColumn", 130);


            listView1.Columns[0].Text = "First name";
            listView1.Columns[1].Text = "Last name";


            using (NorthContext context = new NorthContext())
            {
                var contacts = context.Contacts.ToList();
                foreach (var contact in contacts)
                {
                    var item = new ListViewItem(new []
                    {
                        contact.FirstName,
                        contact.LastName,
                        contact.ContactId.ToString()
                    });
                    listView1.Items.Add(item);
                }
            }

            listView1.Items[0].Selected = true;
            listView1.Select();
            CurrentButton.Enabled = true;
        }
示例#9
0
 public GenericRepository(NorthContext context)
 {
     DbContext = Activator.CreateInstance <TContext>();
     DbContext.Configuration.LazyLoadingEnabled = true;
     _entity = context.Set <TEntity>();
 }
示例#10
0
文件: UowData.cs 项目: nikolovk/north
 public UowData(NorthContext context)
 {
     this.context = context;
 }