public void AddNewOrder(OrderViewModels order) { using (ShopDBEntities db = new ShopDBEntities()) { //string[] formats = { "dd/MM/yyyy" }; //DateTime oDate = new DateTime();// //oDate = DateTime.Parse(order.OrderDate).Date; //.Pars e(order.OrderDate); Order model = new Order(); model.CustomerId = order.CustomerId; model.OrderDate = order.OrderDate; model.OrderNumber = order.OrderNumber; model.TotalAmount = order.TotalAmount; db.Order.Add(model); db.SaveChanges(); foreach (var item in order.ListOrderItem) { OrderItem modelItem = new OrderItem(); modelItem.OrderId = model.Id; modelItem.ProductId = item.ProductId; modelItem.Quantity = item.Quantity; modelItem.UnitPrice = item.UnitPrice; db.OrderItem.Add(modelItem); db.SaveChanges(); } } }
public ActionResult MakeNewUser(User u) { db.Users.Add(u); db.SaveChanges(); return(RedirectToAction("Login")); }
public void CreateNewOrder(OrderViewModel model) { using (ShopDBEntities db = new ShopDBEntities()) { Order order = new Order(); order.OrderDate = model.OrderDate; order.OrderNumber = model.OrderNumber; order.CustomerId = model.CustomerId; order.TotalAmount = model.TotalAmount; db.Order.Add(order); db.SaveChanges(); foreach (var item in model.OrderItem) { OrderItem orderItem = new OrderItem(); orderItem.OrderId = (from p in db.Order orderby p.Id descending select p.Id).First(); orderItem.ProductId = item.ProductId; orderItem.UnitPrice = item.UnitPrice; orderItem.Quantity = item.Quantity; db.OrderItem.Add(orderItem); db.SaveChanges(); } } }
public void AddNewOrder(OrderViewModel order) { using (ShopDBEntities db = new ShopDBEntities()) { string[] formats = { "dd/MM/yyyy" }; DateTime oDate = DateTime.ParseExact(order.OrderDate, formats, new CultureInfo("en-US"), DateTimeStyles.None); Order model = new Order(); model.CustomerId = order.CustomerId; model.OrderDate = oDate; model.OrderNumber = order.OrderNumber; model.TotalAmount = order.TotalAmount; db.Order.Add(model); db.SaveChanges(); foreach (var item in order.ListOrderItem) { OrderItem modelItem = new OrderItem(); modelItem.OrderId = model.Id; modelItem.ProductId = item.ProductId; modelItem.Quantity = item.Quantity; modelItem.UnitPrice = item.UnitPrice; db.OrderItem.Add(modelItem); db.SaveChanges(); } } }
public ActionResult Create([Bind(Include = "Id,barcode,info,price,count")] Item item) { if (ModelState.IsValid) { db.Item.Add(item); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(item)); }
public ActionResult Create([Bind(Include = "UserID,FullName,UserName,Email,Phone,Password,City,State,Country,Address")] UserT userT) { if (ModelState.IsValid) { db.UserTs.Add(userT); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(userT)); }
public ActionResult Create([Bind(Include = "CategorieID,CategorieName,CategorieNameAR,ImagePath")] CategoriesT categoriesT) { if (ModelState.IsValid) { db.CategoriesTs.Add(categoriesT); db.SaveChanges(); return(RedirectToAction("Indexx")); } return(View(categoriesT)); }
public ActionResult Create([Bind(Include = "Id,Name")] ItemType itemType) { if (ModelState.IsValid) { db.ItemType.Add(itemType); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(itemType)); }
public ActionResult Create([Bind(Include = "Id,Role1")] Role role) { if (ModelState.IsValid) { db.Role.Add(role); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(role)); }
public ActionResult Create([Bind(Include = "Id,Login,Info,Password")] User user) { if (ModelState.IsValid) { db.User.Add(user); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }
public ActionResult Create([Bind(Include = "Id,Name")] Provider provider) { if (ModelState.IsValid) { db.Provider.Add(provider); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(provider)); }
public ActionResult Edit(OrderViewModel order) { if (ModelState.IsValid) { db.Entry(order).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CustomerId = new SelectList(db.Customer, "Id", "FirstName", order.CustomerId); return(View(order)); }
public ActionResult Create([Bind(Include = "OrderNumber,ProdectID,ProdectName,ProdectNameAR,Descriotion,DescriotionAR,Price,Rating,ImagePath,CategorieID,UserID,FullName,UserName,Email,Phone,Password,City,State,Country,Address")] oldOrder oldOrder) { if (ModelState.IsValid) { db.oldOrders.Add(oldOrder); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(oldOrder)); }
public ActionResult Create([Bind(Include = "id,Category_id,Name,Price,Count,Description")] Product product) { if (ModelState.IsValid) { db.Product.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Category_id = new SelectList(db.Category, "id", "Name", product.Category_id); return(View(product)); }
public ActionResult Create([Bind(Include = "ImageID,ImagePath,ImageTitle,ProdectID")] ImageT imageT) { if (ModelState.IsValid) { db.ImageTs.Add(imageT); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ProdectID = new SelectList(db.ProdectTs, "ProdectID", "ProdectName", imageT.ProdectID); return(View(imageT)); }
public ActionResult Create([Bind(Include = "Id,Date,Id_Provider,State")] ShopQuest shopQuest) { if (ModelState.IsValid) { db.ShopQuest.Add(shopQuest); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Id_Provider = new SelectList(db.Provider, "Id", "Name", shopQuest.Id_Provider); return(View(shopQuest)); }
public ActionResult Edit(Dessert dessert, HttpPostedFileBase DessertImage2) { //判斷是否有圖片上傳 if (DessertImage2 != null) { //判斷是否為圖片 if (!DessertImage2.ContentType.StartsWith("image")) { ModelState.AddModelError("DessertImage", "只能上傳圖片類型"); } //判斷圖片大小是否>0 else if (DessertImage2.ContentLength > 0) { var fileName = Path.GetFileName(DessertImage2.FileName); //存檔路徑 var path = Path.Combine(Server.MapPath("~/images/"), fileName); //存檔 DessertImage2.SaveAs(path); var editPath = Path.Combine(Server.MapPath("~/images/"), dessert.DessertImage); if (System.IO.File.Exists(editPath)) { System.IO.File.Delete(editPath); } dessert.DessertImage = fileName; } } //找尋原本資料 var SearchDessert = db.Dessert.Find(dessert.DessertID); if (ModelState.IsValid) { //修改原本資料 SearchDessert.DessertImage = dessert.DessertImage; SearchDessert.DessertIntroduction = dessert.DessertIntroduction; SearchDessert.DessertKind = dessert.DessertKind; SearchDessert.DessertName = dessert.DessertName; SearchDessert.DessertPrice = dessert.DessertPrice; SearchDessert.IsOnSale = dessert.IsOnSale; db.Entry(SearchDessert).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } //下拉類別選單 Dictionary <string, string> kind = new Dictionary <string, string>(); kind.Add("Cookie", "餅乾"); kind.Add("Cake", "蛋糕"); kind.Add("Pie", "派"); ViewBag.selectKind = new SelectList(kind, "key", "value", dessert.DessertKind); return(View(dessert)); }
public ActionResult Create([Bind(Include = "Id,Id_item,Id_provider")] Provider_Item provider_Item) { if (ModelState.IsValid) { db.Provider_Item.Add(provider_Item); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Id_item = new SelectList(db.Item, "Id", "barcode", provider_Item.Id_item); ViewBag.Id_provider = new SelectList(db.Provider, "Id", "Name", provider_Item.Id_provider); return(View(provider_Item)); }
public ActionResult Create([Bind(Include = "OrderID,ProdectID,UserID")] OrderT orderT) { if (ModelState.IsValid) { db.OrderTs.Add(orderT); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ProdectID = new SelectList(db.ProdectTs, "ProdectID", "ProdectName", orderT.ProdectID); ViewBag.UserID = new SelectList(db.UserTs, "UserID", "FullName", orderT.UserID); return(View(orderT)); }
public ActionResult Create([Bind(Include = "Id,Id_Item,Id_ItemType")] Item_Type item_Type) { if (ModelState.IsValid) { db.Item_Type.Add(item_Type); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Id_Item = new SelectList(db.Item, "Id", "barcode", item_Type.Id_Item); ViewBag.Id_ItemType = new SelectList(db.ItemType, "Id", "Name", item_Type.Id_ItemType); return(View(item_Type)); }
public ActionResult Create([Bind(Include = "UserItemId,UserID,ItemID")] UserItem userItem) { if (ModelState.IsValid) { db.UserItems.Add(userItem); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ItemID = new SelectList(db.Items, "id", "Name", userItem.ItemID); ViewBag.UserID = new SelectList(db.Users, "id", "UserName", userItem.UserID); return(View(userItem)); }
public ActionResult Create([Bind(Include = "Id,Id_Item,Id_ShopQuest,Count")] ShopQuest_item shopQuest_item) { if (ModelState.IsValid) { db.ShopQuest_item.Add(shopQuest_item); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Id_Item = new SelectList(db.Item, "Id", "barcode", shopQuest_item.Id_Item); ViewBag.Id_ShopQuest = new SelectList(db.ShopQuest, "Id", "Id", shopQuest_item.Id_ShopQuest); return(View(shopQuest_item)); }
public ActionResult Create([Bind(Include = "Id,Id_User,Id_Role")] User_Role user_Role) { if (ModelState.IsValid) { db.User_Role.Add(user_Role); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Id_Role = new SelectList(db.Role, "Id", "Role1", user_Role.Id_Role); ViewBag.Id_User = new SelectList(db.User, "Id", "Login", user_Role.Id_User); return(View(user_Role)); }
public ActionResult Create([Bind(Include = "ProdectID,ProdectName,ProdectNameAR,Descriotion,DescriotionAR,Price,Rating,ImagePath,CategorieID")] ProdectT prodectT) { //string FileName = Path.GetFileNameWithoutExtension(prodectT.) if (ModelState.IsValid) { db.ProdectTs.Add(prodectT); db.SaveChanges(); return(RedirectToAction("Indexx")); } ViewBag.CategorieID = new SelectList(db.CategoriesTs, "CategorieID", "CategorieName", prodectT.CategorieID); return(View(prodectT)); }
public ActionResult CreateQuest([Bind(Include = "Id,key")] Quest quest) { if (ModelState.IsValid) { DateTime r = DateTime.Now; quest.Date = r; quest.LastEdit = r; db.Quest.Add(quest); quest.State = 1; db.SaveChanges(); Session["QuestID"] = quest.Id; return(RedirectToAction("Quest")); } return(View(quest)); }
public ActionResult Register(MemberViewModel MemberData) { var checkAccount = db.member.Where(x => x.Account == MemberData.Account).Count(); if (this.IsCaptchaValid("驗證碼錯誤")) { if (checkAccount < 0) { ModelState.AddModelError("Account", "此帳號已經有人使用"); } if (ModelState.IsValid) { db.member.Add(new member() { Account = MemberData.Account, Email = MemberData.Email, Adress = MemberData.Adress, Name = MemberData.Name, Telphone = MemberData.Telphone, PassWord = MemberData.PassWord, isAdmin = false, }); db.SaveChanges(); TempData["Success"] = "註冊成功,你現在可以登入了"; return(RedirectToAction("Index", "MemberPage")); } } return(View(MemberData)); }
public void AddNewCustomer(CustomerViewModel customer) { using (ShopDBEntities db = new ShopDBEntities()) { using (var dbContextTransaction = db.Database.BeginTransaction()) { try { Customer model = new Customer(); model.FirstName = customer.FirstName; model.LastName = customer.LastName; model.City = customer.City; model.Country = customer.Country; model.Phone = customer.Phone; model.Email = customer.Email; db.Customer.Add(model); db.SaveChanges(); dbContextTransaction.Commit(); } catch (Exception) { dbContextTransaction.Rollback(); } } } }
private void SetUserRating(float val) { string userID = Request.Form["userID"]; string voterID = Request.Form["voterID"]; using (ShopDBEntities db = new ShopDBEntities()) { if (db.UserRaiting.Any(m => m.UserID == userID && m.VoterID == voterID)) { var userRaiting = db.UserRaiting.First(m => m.UserID == userID && m.VoterID == voterID); if (userRaiting.Rating != val) { Response.Write("raiting changed"); userRaiting.Rating = val; } else { Response.Write("nothing changed"); } } else { Response.Write("new raiting"); db.UserRaiting.Add(new UserRaiting() { UserID = userID, VoterID = voterID, Rating = val }); } db.SaveChanges(); } }
public void CreateOrder(OrderViewModel item) { using (ShopDBEntities db = new ShopDBEntities()) { int Id = (db.Order.ToList().Count != 0) ? (from o in db.Order orderby o.Id descending select o.Id).First() + 1 : 1; Order order = new Order(); order.OrderDate = item.OrderDate; order.OrderNumber = item.OrderNumber; order.CustomerId = item.CustomerId; order.TotalAmount = item.TotalAmount; db.Order.Add(order); OrderItem orderitem = new OrderItem(); foreach (var things in item.orderItem) { orderitem.OrderId = Id; orderitem.ProductId = things.ProductId; orderitem.UnitPrice = things.UnitPrice; orderitem.Quantity = things.Quantity; db.OrderItem.Add(orderitem); db.SaveChanges(); } } }
private void brnProcess_Click(object sender, EventArgs e) { try { int CompleteOStatusID = Convert.ToInt32(Properties.Settings.Default["CompleteOStatusID"]); int PendingOStatusID = Convert.ToInt32(Properties.Settings.Default["PendingOStatusID"]); using (ShopDBEntities db = new ShopDBEntities()) { string prderNo = txtOrderNo.Text; var toUpdate = db.Orders.SingleOrDefault(c => c.OrderNo == prderNo); toUpdate.TotalPayment = Convert.ToDecimal(txtTotalPayment.Text); toUpdate.PaymentDue = Convert.ToDecimal(txtPaymentDue.Text); if (Convert.ToDecimal(txtPaymentDue.Text) == 0) { toUpdate.OrderStatusID = CompleteOStatusID; } else { toUpdate.OrderStatusID = PendingOStatusID; } db.Entry(toUpdate).State = EntityState.Modified; db.SaveChanges(); MessageBox.Show("Updated successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } catch (Exception ex) { MessageBox.Show("Error.\nDetails: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; txtOrderNo.Focus(); } }