public ActionResult Delete() { // Create New Objects. ShopDal sdal = new ShopDal(); NewProductViewModel npvm = new NewProductViewModel(); NewProduct np = new NewProduct(); int flag = 0; // The list of products from Db. List <NewProduct> objProduct = sdal.NewproductDB.ToList <NewProduct>(); // Take all the values the manger want to update. np.ProductId = Request.Form["newproduct.ProductId"].ToString(); // find the product we are looking for by ProductId. foreach (NewProduct ob in objProduct) { if (np.ProductId == ob.ProductId) { // remove the product we want form the list. sdal.NewproductDB.Remove(ob); sdal.SaveChanges(); flag = 1; } } if (flag == 0) { TempData["errorId2"] = "The Id Product is not in the list."; } return(View("MangerPanel")); }
public ActionResult LoginManger() { // Making new Conection to Db ShopDal sdal = new ShopDal(); // take the values from Db List <Manger> objProduct = sdal.lgoinDb.ToList <Manger>(); return(View("LoginManger")); }
public ActionResult About() { ShopDal shdal = new ShopDal(); CustomerViewModel cvm = new CustomerViewModel(); cvm.shops = shdal.Shops.ToList <Shop>(); return(View(cvm)); }
// Table for Customers. public ActionResult GetOrdersByJson() { ShopDal sdal = new ShopDal(); // take the values from Db List <Customer> objProduct = sdal.CustomerDB.ToList <Customer>(); Thread.Sleep(5000); // return data with json. return(Json(objProduct, JsonRequestBehavior.AllowGet)); }
//Table for Products. public ActionResult GetProductsByJson() { ShopDal sdal = new ShopDal(); // take the values from Db List <NewProduct> objProduct = sdal.NewproductDB.ToList <NewProduct>(); Thread.Sleep(5000); // return data with json. return(Json(objProduct, JsonRequestBehavior.AllowGet)); }
public ActionResult MangerPanel() { // Making new Conection to Db ShopDal sdal = new ShopDal(); // take the values from Db List <NewProduct> objProduct = sdal.NewproductDB.ToList <NewProduct>(); NewProductViewModel npvm = new NewProductViewModel(); npvm.newproduct = new NewProduct(); npvm.newproducts = objProduct; return(View(npvm)); }
public ActionResult SerachCustomers() { // Connection to Db. ShopDal sdal = new ShopDal(); int searchMinNumber = 0; int searchMaxNumber = 0; // Get the Name form the Search-TextBox. string searchName = Request.Form["txtFirstName1"].ToString(); //Check if the Numbers are "empty" equals to zero. if (Request.Form["txtFirstName2"] == "" && Request.Form["txtFirstName3"] == "") { searchMinNumber = 0; searchMaxNumber = 0; } else // if not and we deside to serach bye numbers { searchMinNumber = int.Parse(Request.Form["txtFirstName2"]); searchMaxNumber = int.Parse(Request.Form["txtFirstName3"]); } NewProductViewModel npv = new NewProductViewModel(); //Go to Db , and Request all the values that we looking for. if (Request.Form["txtFirstName1"] != "") { List <NewProduct> ObjProduct1 = (from x in sdal.NewproductDB // if the name is equals to the name in the DataBsee , show it. where x.ProductName.ToString() == searchName select x).ToList <NewProduct>(); npv.newproducts = ObjProduct1; } else // looking for numbers that start with (min) , and End with(Max). { List <NewProduct> ObjProduct2 = (from x in sdal.NewproductDB where x.Price >= searchMinNumber && x.Price <= searchMaxNumber select x).ToList <NewProduct>(); npv.newproducts = ObjProduct2; } // if the Customer send empty values to seacrh it will return the same web. if (searchName.Length == 0 && searchMinNumber == 0 && searchMaxNumber == 0) { return(RedirectToAction("HomeWeb")); } return(View("HomeWeb", npv)); }
public ActionResult HomeWeb() { // Make new Connection to DataBase ShopDal sdal = new ShopDal(); // make a list from all the data(NewProdect) in the Db. List <NewProduct> objProduct = sdal.NewproductDB.ToList <NewProduct>(); // object type New Product ViewModel. NewProductViewModel npvm = new NewProductViewModel(); npvm.newproduct = new NewProduct(); //take the list the we got , and show it in the Home Web. npvm.newproducts = objProduct; return(View(npvm)); }
public ActionResult Submit() { NewProductViewModel npvm = new NewProductViewModel(); NewProduct objNewProduct = new NewProduct(); int flag = 0; // Take all the values the manger insert. objNewProduct.ProductName = Request.Form["newproduct.ProductName"].ToString(); objNewProduct.Price = int.Parse(Request.Form["newproduct.Price"]); objNewProduct.InitialQuantity = Request.Form["newproduct.InitialQuantity"].ToString(); objNewProduct.ProductId = Request.Form["newproduct.ProductId"].ToString(); ShopDal sdal = new ShopDal(); List <NewProduct> objProduct = sdal.NewproductDB.ToList <NewProduct>(); // Check if the ProductId allready in use foreach (NewProduct ob in objProduct) { if (objNewProduct.ProductId == ob.ProductId) { flag = 1; TempData["Message"] = "Error This key is already in used"; } } // if the ProductId is not in used save the new Product in Db if (ModelState.IsValid && flag == 0) { sdal.NewproductDB.Add(objNewProduct); sdal.SaveChanges(); npvm.newproduct = new NewProduct(); } else { // if the manger insert wrong values, save tha data and Present it again. npvm.newproduct = objNewProduct; } // send the new list to the web , for the manger can show it. npvm.newproducts = sdal.NewproductDB.ToList <NewProduct>(); return(View("MangerPanel", npvm)); }
public ActionResult Update(NewProduct obj) { ShopDal sdal = new ShopDal(); NewProductViewModel npvm = new NewProductViewModel(); List <NewProduct> objProduct = sdal.NewproductDB.ToList <NewProduct>(); int flag = 0; // Take all the values the manger want to update. obj.ProductId = Request.Form["newproduct.ProductId"].ToString(); obj.InitialQuantity = Request.Form["newproduct.InitialQuantity"].ToString(); //Check if the Id in the list. foreach (NewProduct ob in objProduct) { if (obj.ProductId == ob.ProductId) { flag = 1; } } if (flag == 0) { TempData["errorId"] = "The Id Product is not in the list."; return(View("MangerPanel")); } // find the product we are looking for by ProductId. NewProduct np1 = (from x in sdal.NewproductDB where x.ProductId == obj.ProductId select x).ToList <NewProduct>()[0]; // update the new Amount np1.InitialQuantity = obj.InitialQuantity; // Save the changes. sdal.SaveChanges(); // return to the MangerPanel. return(View("MangerPanel")); }
public ActionResult Login() { ShopDal sdal = new ShopDal(); Manger M = new Manger(); List <Manger> objProduct = sdal.lgoinDb.ToList <Manger>(); // Take the values from the TextBox that the user/Manger Enter. M.Username = Request.Form["user.Username"].ToString(); M.Password = Request.Form["user.Password"].ToString(); // check if the username and the password are in the DB. foreach (Manger ob in objProduct) { // if they are in the Db go to MangerPanel if (M.Username == ob.Username && M.Password == ob.Password) { return(View("MangerPanel")); } } // Otherwise return to the Home Web. return(RedirectToAction("HomeWeb", "Home")); }
public static int GetTopShopModel() { string exceptionUri = ""; int exceptionShopID = 0; List <ShopModel> list = ShopDal.GetTopShopModel(); if (list.Count == 0) { return(1); } //Thread.Sleep(5000); try { foreach (ShopModel model in list) { BaiDuCoordinate bd_Coor = BaiduCoordinateTrans.GCJ2Baidu(model.Longitude, model.Latitude); /*个别经纬度格式不对*/ StringBuilder sb = new StringBuilder(); sb.Append("http://api.map.baidu.com/geocoder/v2/?"); sb.Append("latest_admin=1&"); sb.Append("extensions_town=true&"); sb.Append("ak=" + Const.BaiduAK + "&"); sb.Append("callback=renderReverse&"); //sb.Append("location=22.939708,113.951647&"); sb.Append("location=" + bd_Coor.Latitude + "," + bd_Coor.Longitude + "&"); sb.Append("output=xml&"); sb.Append("pois=0"); exceptionUri = sb.ToString(); exceptionShopID = model.ShopID; model.bd_Latitude = bd_Coor.Latitude; model.bd_Longitude = bd_Coor.Longitude; model.Uri = sb.ToString(); string result = WebHandler.GetHtmlStr(sb.ToString(), "UTF8"); if (result == "") { ShopDal.UpdateLongLat(model, 2);/*异常*/ continue; } XmlDocument doc = new XmlDocument(); doc.LoadXml(result); string statusPath = "/GeocoderSearchResponse/status"; string rootPath = "/GeocoderSearchResponse/result/addressComponent"; XmlElement root = doc.DocumentElement; if (root.SelectNodes(statusPath)[0].InnerText == "0") // 成功 { XmlNodeList listNodes = root.SelectNodes(rootPath); string country = root.SelectNodes(rootPath + "/country")[0].InnerText; string province = root.SelectNodes(rootPath + "/province")[0].InnerText; string city = root.SelectNodes(rootPath + "/city")[0].InnerText; string district = root.SelectNodes(rootPath + "/district")[0].InnerText; string town = root.SelectNodes(rootPath + "/town")[0].InnerText; string street = root.SelectNodes(rootPath + "/street")[0].InnerText; model.Province = province; model.CityID = city; model.County = district; model.Town = town; model.Address = street; ShopDal.Update(model, 1); } else { ShopDal.UpdateLongLat(model, 2);/*异常*/ } } } catch (Exception ex) { ShopDal.UpdateState(exceptionShopID, exceptionUri, 3);/*程序异常*/ LogUtil.WriteInfo(ex.Message); LogUtil.WriteInfo("exceptionHtml=" + exceptionUri); } return(0); }
public ActionResult Submit() { ShopDal sdal = new ShopDal(); Customer cus = new Customer(); string amount = ""; DateTime TimeNow = DateTime.Now; List <NewProduct> objProduct = sdal.NewproductDB.ToList <NewProduct>(); // Check if the object is Valid. if (ModelState.IsValid) { // check if the customer name is less than two letter's. if (Request.Form["name"].Length != 0 && Request.Form["name"].Length != 1 && Regex.IsMatch(Request["name"], @"^[a-zA-Z]+$")) { // if not save the name. cus.CustomerName = Request.Form["name"]; } else { TempData["error"] = "Insert Correct Name between 2 and 10 words."; return(RedirectToAction("HomeWeb", TempData["error"])); } // save the id of the prodect the customer bought. string id = Request.Form["ko"]; // Amount of product to buy 1-5. string Amount = Request.Form["testSelect"]; foreach (NewProduct ob in objProduct) { // find the id that we take from the list. if (id == ob.ProductId) { // Save the name of the customer cus.ProductName = ob.ProductName; // Save the Amount cus.Quantity = Amount; //Subtract the Amount the customer bought from list. amount = (int.Parse(ob.InitialQuantity) - int.Parse(Amount)).ToString(); // save the time is purchase cus.Date = TimeNow.ToString(); } } // Check if it Ok if (ModelState.IsValid) { // Add the Customer to Db. sdal.CustomerDB.Add(cus); sdal.SaveChanges(); } // find the product , the custoemr bought NewProduct np1 = (from x in sdal.NewproductDB where x.ProductId == id select x).ToList <NewProduct>()[0]; // Update the new Amount of the Product. np1.InitialQuantity = amount; sdal.SaveChanges(); // Return to the same page return(View("CustomerName")); } else { return(RedirectToAction("HomeWeb")); } }