コード例 #1
0
ファイル: Global.asax.cs プロジェクト: kiddykooly/ZaZi
        private void PrepareCustomerList()
        {
            XmlDocument xml = new XmlDocument();
            xml.Load(Server.MapPath("~/App_Data/customers.xml"));
            XmlNodeList customers = xml.SelectNodes("/customers/customer");
            foreach (XmlNode item in customers)
            {
                CustomerModel c = new CustomerModel();
                c.Id = int.Parse(item.Attributes["id"].Value);
                c.Email = item.Attributes["email"].Value;
                c.FullName = item.Attributes["name"].Value;

                CustomerList.Add(c);
            }
        }
コード例 #2
0
ファイル: HomeController.cs プロジェクト: kiddykooly/ZaZi
        public ActionResult InsertBid(TempleModel model)
        {
            //int k = getNumUser();

            CustomerModel customer = getCustomerByEmail(model.Email);
            BidModel bid;
            // Nếu giá thấp hơn giá hiện tại thì next
            if (ZaZi.MvcApplication.ProductList[ZaZi.MvcApplication.productId].CurrentPrice >= model.BidPrice)
            {
                return Json(new { Status = 1 });
            }
            if (customer != null)
            {
                customer.FullName = model.Name;
                InsertOrUpdateCustomer(customer, false);
                if (model.remember != null)
                {
                    Session["id"] = customer.Id;
                    Session["name"] = customer.FullName;
                    Session["mail"] = customer.Email;
                }
                bid = getBidModel(customer.Id, model.Id);
                if (bid == null)
                {
                    bid = new BidModel();
                    bid.Id = ZaZi.MvcApplication.BidList.Count + 1;
                    bid.CustomerId = customer.Id;
                    bid.ProductId = model.Id;
                    bid.BidPrice = model.BidPrice;
                    bid.Time = DateTime.Now;
                    ZaZi.MvcApplication.WinnerName = customer.FullName;
                    InsertOrUpdateBid(bid, true);
                }
                else
                {
                    bid.BidPrice = model.BidPrice;
                    bid.Time = DateTime.Now;
                    ZaZi.MvcApplication.WinnerName = customer.FullName;
                    InsertOrUpdateBid(bid, false);
                }

            }
            else
            {
                //ZaZi.MvcApplication.currentUser += 1;
                customer = new CustomerModel();
                customer.Id = ZaZi.MvcApplication.CustomerList.Count + 1;
                customer.Email = model.Email;
                customer.FullName = model.Name;
                InsertOrUpdateCustomer(customer, true);
                // Dùng cho việc ghi nhớ thôgn tin đăng nhập
                if (model.remember != null)
                {
                    Session["id"] = customer.Id;
                    Session["name"] = customer.FullName;
                    Session["mail"] = customer.Email;
                }
                bid = new BidModel();
                bid.Id = ZaZi.MvcApplication.BidList.Count + 1;
                bid.CustomerId = customer.Id;
                bid.ProductId = model.Id;
                bid.BidPrice = model.BidPrice;
                bid.Time = DateTime.Now;
                ZaZi.MvcApplication.WinnerName = customer.FullName;
                InsertOrUpdateBid(bid, true);
            }

            UpdateProductPrice(bid);
            return Json(new { Status = 1});
        }
コード例 #3
0
ファイル: HomeController.cs プロジェクト: kiddykooly/ZaZi
        private void InsertOrUpdateCustomer(CustomerModel customer, bool insert)
        {
            XmlDocument xml = new XmlDocument();
            xml.Load(Server.MapPath("~/App_Data/customers.xml"));
            if (insert)
            {
                ZaZi.MvcApplication.CustomerList.Add(customer);

                XmlNode customers = xml.SelectSingleNode("customers");
                XmlNode c = xml.CreateNode(XmlNodeType.Element, "customer", null);

                XmlAttribute id = xml.CreateAttribute("id");
                id.Value = customer.Id.ToString();

                XmlAttribute email = xml.CreateAttribute("email");
                email.Value = customer.Email;

                XmlAttribute name = xml.CreateAttribute("name");
                name.Value = customer.FullName;

                c.Attributes.Append(id);
                c.Attributes.Append(email);
                c.Attributes.Append(name);

                customers.AppendChild(c);
            }
            else
            {
                ZaZi.MvcApplication.CustomerList.Find(x => x.Id == customer.Id).FullName = customer.FullName;

                XmlNodeList customers = xml.SelectNodes("/customers/customer");
                foreach (XmlNode item in customers)
                {
                    if (int.Parse(item.Attributes["id"].Value) == customer.Id)
                    {
                        item.Attributes["name"].Value = customer.FullName;
                        break;
                    }
                }
            }

            xml.Save(Server.MapPath("~/App_Data/customers.xml"));
        }