コード例 #1
0
        public ActionResult Create([Bind(Include = "ProductID,ProductName,Weight,Ingredient")] Product product)
        {
            if (ModelState.IsValid)
            {
                db.Product.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(product));
        }
コード例 #2
0
        public ActionResult Create([Bind(Include = "ID,OrderID,Owner,DealerID,ShippingData,ProductName,MFD,Lisence,Declaration,EXP,Discription,Amount,Volume,Weight,Code,Driver,CarNum")] OutboundData outboundData)
        {
            if (ModelState.IsValid)
            {
                db.OutboundData.Add(outboundData);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(outboundData));
        }
コード例 #3
0
        public ActionResult Create([Bind(Include = "ImportDataID,ProductID,MFD,EXP,Lisence,Declaration,Item,PurchaseNum")] ImportData importData)
        {
            if (ModelState.IsValid)
            {
                db.ImportData.Add(importData);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ProductID = new SelectList(db.Product, "ProductID", "ProductName", importData.ProductID);
            return(View(importData));
        }
コード例 #4
0
        /// <summary>
        /// Saves the import data.
        /// </summary>
        /// <param name="importZipCodes">The import zip codes.</param>
        /// <exception cref="System.NotImplementedException"></exception>
        public void SaveImportData(IEnumerable <OutboundData> importZipCodes)
        {
            try
            {
                //先砍掉全部資料
                using (var db = new TestDataEntities())
                {
                    foreach (var item in db.OutboundData.OrderBy(x => x.ID))
                    {
                        db.OutboundData.Remove(item);
                    }
                    db.SaveChanges();
                }

                //再把匯入的資料給存到資料庫
                using (var db = new TestDataEntities())
                {
                    foreach (var item in importZipCodes)
                    {
                        db.OutboundData.Add(item);
                    }
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
コード例 #5
0
ファイル: Login.aspx.cs プロジェクト: TarunJain81/Projects
    protected void Button1_Click(object sender, EventArgs e)
    {
        string sname = TextBox1.Text;

        using (var context = new TestDataEntities())
        {
            var user = (from u in context.Scores
                        where u.Name == sname
                        select u.Name).FirstOrDefault();

            if (user != null)
            {
                Session["Username"] = Label1.Text;
                Response.Redirect("Exam.aspx");
            }
            else
            {
                Score s = new Score
                {
                    Name  = sname,
                    Marks = 0,
                };
                context.Scores.Add(s);
                context.SaveChanges();
                Session["Username"] = Label1.Text;
                Response.Redirect("Exam.aspx");
            }
        }
    }
コード例 #6
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        using (var context = new TestDataEntities())
        {
            Question q = new Question
            {
                QuizId  = 10,
                Quest   = TextBox1.Text,
                Answers = TextBox2.Text,
                Ans     = TextBox3.Text,
                Level   = Convert.ToInt32(TextBox4.Text)
            };

            context.Questions.Add(q);
            context.SaveChanges();
        }
    }