public ActionResult CreateQuick([Bind(Include = "Id,TypeNo,TypeName,Description")] BusinessRuleType businessruletype, string UrlReferrer)
 {
     if (ModelState.IsValid)
     {
         db.BusinessRuleTypes.Add(businessruletype);
         db.SaveChanges();
         return(Redirect(Request.UrlReferrer.ToString()));
     }
     return(View(businessruletype));
 }
        // GET: /BusinessRuleType/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BusinessRuleType businessruletype = db.BusinessRuleTypes.Find(id);

            if (businessruletype == null)
            {
                return(HttpNotFound());
            }
            return(View(businessruletype));
        }
 public ActionResult EditWizard([Bind(Include = "Id,TypeNo,TypeName,Description")] BusinessRuleType businessruletype, string UrlReferrer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(businessruletype).State = EntityState.Modified;
         db.SaveChanges();
         if (!string.IsNullOrEmpty(UrlReferrer))
         {
             return(Redirect(UrlReferrer));
         }
         else
         {
             return(RedirectToAction("Index"));
         }
     }
     return(View(businessruletype));
 }
 public ActionResult Create([Bind(Include = "Id,TypeNo,TypeName,Description")] BusinessRuleType businessruletype, string UrlReferrer)
 {
     if (ModelState.IsValid)
     {
         db.BusinessRuleTypes.Add(businessruletype);
         db.SaveChanges();
         if (!string.IsNullOrEmpty(UrlReferrer))
         {
             return(Redirect(UrlReferrer));
         }
         else
         {
             return(RedirectToAction("Index"));
         }
     }
     return(View(businessruletype));
 }
        public ActionResult DeleteConfirmed(int id)
        {
            if (!User.CanDelete("BusinessRuleType"))
            {
                return(RedirectToAction("Index", "Error"));
            }
            BusinessRuleType businessruletype = db.BusinessRuleTypes.Find(id);

            db.BusinessRuleTypes.Remove(businessruletype);
            db.SaveChanges();
            if (ViewData["BusinessRuleTypeParentUrl"] != null)
            {
                string parentUrl = ViewData["BusinessRuleTypeParentUrl"].ToString();
                ViewData["BusinessRuleTypeParentUrl"] = null;
                return(Redirect(parentUrl));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }
        // GET: /BusinessRuleType/Delete/5
        public ActionResult Delete(int?id)
        {
            if (!User.CanDelete("BusinessRuleType"))
            {
                return(RedirectToAction("Index", "Error"));
            }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BusinessRuleType businessruletype = db.BusinessRuleTypes.Find(id);

            if (businessruletype == null)
            {
                return(HttpNotFound());
            }
            if (ViewData["BusinessRuleTypeParentUrl"] == null && Request.UrlReferrer != null && !Request.UrlReferrer.AbsolutePath.EndsWith("/BusinessRuleType"))
            {
                ViewData["BusinessRuleTypeParentUrl"] = Request.UrlReferrer;
            }
            return(View(businessruletype));
        }
        public ActionResult ImportData(FormCollection collection)
        {
            string FilePath              = collection["hdnFilePath"];
            var    columnlist            = collection["lblColumn"];
            var    selectedlist          = collection["colList"];
            string fileLocation          = FilePath;
            string excelConnectionString = string.Empty;
            string fileExtension         = System.IO.Path.GetExtension(fileLocation);

            if (fileExtension == ".xls" || fileExtension == ".xlsx")
            {
                if (fileExtension == ".xls")
                {
                    excelConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";
                }
                else if (fileExtension == ".xlsx")
                {
                    excelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
                }
                OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);
                excelConnection.Open();
                DataTable dt = new DataTable();
                dt = excelConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                if (dt == null)
                {
                    return(null);
                }
                String[] excelSheets = new String[dt.Rows.Count];
                int      t           = 0;
                foreach (DataRow row in dt.Rows)
                {
                    excelSheets[t] = row["TABLE_NAME"].ToString();
                    t++;
                }
                excelConnection.Close();
                OleDbConnection excelConnection1 = new OleDbConnection(excelConnectionString);
                DataSet         objDataSet       = new DataSet();
                string          query            = string.Format("Select * from [{0}]", excelSheets[0]);
                using (OleDbDataAdapter dataAdapter = new OleDbDataAdapter(query, excelConnection1))
                {
                    dataAdapter.Fill(objDataSet);
                }
                excelConnection1.Close();
                if (selectedlist != null && columnlist != null)
                {
                    for (int i = 0; i < objDataSet.Tables[0].Rows.Count; i++)
                    {
                        BusinessRuleType model = new BusinessRuleType();
                        var tblColumns         = columnlist.Split(',').ToList();
                        var sheetColumns       = selectedlist.Split(',').ToList();
                        for (int j = 0; j < sheetColumns.Count; j++)
                        {
                            string columntable = tblColumns[j];
                            int    columnSheet = 0;
                            if (string.IsNullOrEmpty(sheetColumns[j]))
                            {
                                continue;
                            }
                            else
                            {
                                columnSheet = Convert.ToInt32(sheetColumns[j]) - 1;
                            }
                            string columnValue = objDataSet.Tables[0].Rows[i][columnSheet].ToString();
                            if (string.IsNullOrEmpty(columnValue))
                            {
                                continue;
                            }
                            switch (columntable)
                            {
                            case "TypeNo":
                                model.TypeNo = Int32.Parse(columnValue);
                                break;

                            case "TypeName":
                                model.TypeName = columnValue;
                                break;

                            default:
                                break;
                            }
                        }
                        db.BusinessRuleTypes.Add(model);
                    }
                    try
                    {
                        db.SaveChanges();
                    }
                    catch {  }
                }
                return(RedirectToAction("Index"));
            }
            return(View());
        }