public ActionResult Create(Jeans jeans)
        {
            if (ModelState.IsValid)
            {
                db.Jeanses.Add(jeans);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.JeansCategoryID = new SelectList(db.JeansCategories, "JeansCategoryID", "strCategory", jeans.JeansCategoryID);
            return(View(jeans));
        }
Beispiel #2
0
        public ActionResult ImportJeansItems(string tbFilePath)
        {
            string strResponse;

            if (!string.IsNullOrEmpty(tbFilePath))
            {
                try
                {
                    System.Xml.Linq.XDocument xmlDoc = System.Xml.Linq.XDocument.Load(tbFilePath);

                    var Jeanses = from g in xmlDoc.Descendants("Jeans")
                                  select g;

                    foreach (var Jeans in Jeanses)
                    {
                        Jeans newJeans = new Jeans();
                        newJeans.Details         = Jeans.Element("Details").Value;
                        newJeans.Jeans_Name      = Jeans.Element("Name").Value;
                        newJeans.JeansCategoryID = Convert.ToInt32(Jeans.Element("Category").Value);
                        newJeans.Price           = Convert.ToInt32(Jeans.Element("Price").Value);
                        db.Jeanses.Add(newJeans);
                        db.SaveChanges();
                    }
                    strResponse = "<font style='font-size:18pt;'><b>Jeans items added successfully in the database.</b><br><br><br></font>";
                }
                catch (System.Exception ex)
                {
                    strResponse = "<font style='font-size:18pt;color:red;'><b>Invalid file path.</b><br><br><br></font>";
                }
            }
            else
            {
                strResponse = "<font style='font-size:18pt;color:red;'><b>Please specify a valid file path.</b><br><br><br></font>";
            }
            ViewBag.response = strResponse;
            return(View());
        }