Exemplo n.º 1
0
        // GET: Equipment - Retrieve all details
        public ActionResult Index()
        {
            DatabaseHandles handles = new DatabaseHandles();

            ModelState.Clear();
            return(View(handles.GetEquipment()));
        }
Exemplo n.º 2
0
        public ActionResult Create(HttpPostedFileBase postedFile)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    string filePath = string.Empty;
                    if (postedFile != null)
                    {
                        string path = Server.MapPath("~/Uploads/");
                        if (!Directory.Exists(path))
                        {
                            Directory.CreateDirectory(path);
                        }

                        filePath = path + Path.GetFileName(postedFile.FileName);
                        string extension = Path.GetExtension(postedFile.FileName);
                        postedFile.SaveAs(filePath);

                        DataTable       dt;
                        DatabaseHandles handles = new DatabaseHandles();
                        handles.ReadExcel(filePath, extension, out dt);

                        int rowUploadCount = handles.AddEquipment(dt);
                        ViewBag.RowsCount = "You have uploaded " + rowUploadCount + " rows";
                    }
                    else
                    {
                        ViewBag.ErrorMess = "You must choose a file!";
                    }
                }

                return(View());
            }
            catch
            {
                return(new HttpNotFoundResult());
            }
        }