public ActionResult AddNewScript(PromoScript ps)
        {
            ActiveDirectoryWeb ad = new ActiveDirectoryWeb();

            string[] usr = ad.SearchActiveDirectory(HttpContext.User.Identity.Name).Split('|');
            ViewBag.IsAdmin = DataAccess.AdminAccess(usr[1]);
            try
            {
                string logI = HttpContext.User.Identity.Name;
                int    ret  = ScriptDataAccess.SaveNewScript(ps, logI.Split('\\').LastOrDefault());
                if (ret > 0)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ViewData["Err"] = "Script Template Already Exist!";
                }
            }
            catch (Exception ex)
            {
                ViewData["Err"] = ex.Message;
            }
            return(View(ps));
        }
Beispiel #2
0
 public static int SaveNewScript(PromoScript ps, string userId)
 {
     using (SqlConnection scon = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLConn"].ConnectionString))
     {
         if (scon.State == ConnectionState.Closed)
         {
             scon.Open();
         }
         SqlCommand cmd = new SqlCommand();
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.Connection  = scon;
         cmd.CommandText = "usp_InsertScript";
         cmd.Parameters.AddWithValue("@ScriptCode", ps.ScriptTemplate);
         cmd.Parameters.AddWithValue("@ScriptName", string.IsNullOrEmpty(ps.ScriptName) ? "" : ps.ScriptName);
         cmd.Parameters.AddWithValue("@BiScriptCode", string.IsNullOrEmpty(ps.BiScriptCode) ? "" : ps.BiScriptCode);
         cmd.Parameters.AddWithValue("@Description", string.IsNullOrEmpty(ps.Description) ? "" : ps.Description);
         cmd.Parameters.AddWithValue("@CoreOfferSalesTax", string.IsNullOrEmpty(ps.CoreOfferSalesTax) ? "" : ps.CoreOfferSalesTax);
         cmd.Parameters.AddWithValue("@CrossSaleTax", string.IsNullOrEmpty(ps.CrossSalesTax) ? "" : ps.CrossSalesTax);
         cmd.Parameters.AddWithValue("@BrandCode", string.IsNullOrEmpty(ps.BrandCode) ? "" : ps.BrandCode);
         cmd.Parameters.AddWithValue("@UserId", userId);
         SqlParameter Result = new SqlParameter();
         Result.ParameterName = "@Result";
         Result.Direction     = ParameterDirection.Output;
         Result.SqlDbType     = SqlDbType.Int;
         cmd.Parameters.Add(Result);
         cmd.ExecuteNonQuery();
         int ret = Convert.ToInt32(Result.Value);
         return(ret);
     }
 }
Beispiel #3
0
        public static List <PromoScript> GetScripts()
        {
            List <PromoScript> retVal = new List <PromoScript>();

            using (SqlConnection scon = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLConn"].ConnectionString))
            {
                try
                {
                    if (scon.State == ConnectionState.Closed)
                    {
                        scon.Open();
                    }
                    SqlCommand cmd = new SqlCommand();
                    cmd.CommandType = CommandType.Text;
                    cmd.Connection  = scon;
                    cmd.CommandText = "SELECT * FROM [Script] order by ScriptName";

                    SqlDataReader rdr = cmd.ExecuteReader();
                    while (rdr.Read())
                    {
                        PromoScript sc = new PromoScript();
                        sc.ScriptTemplate    = rdr["ScriptCode"].ToString();
                        sc.ScriptName        = rdr["ScriptName"].ToString();
                        sc.BiScriptCode      = rdr["BiScriptCode"].ToString();
                        sc.Description       = rdr["Description"].ToString();
                        sc.CoreOfferSalesTax = rdr["CoreOfferSalesTax"].ToString();
                        sc.CrossSalesTax     = rdr["CrossSaleTax"].ToString();
                        retVal.Add(sc);
                    }
                }
                catch (Exception) { throw; }
            }
            return(retVal);
        }
        public ActionResult EditScript(PromoScript ps, string OldScriptCode)
        {
            ActiveDirectoryWeb ad = new ActiveDirectoryWeb();

            string[] usr = ad.SearchActiveDirectory(HttpContext.User.Identity.Name).Split('|');
            ViewBag.IsAdmin = DataAccess.AdminAccess(usr[1]);
            string logI = HttpContext.User.Identity.Name;

            try
            {
                ScriptDataAccess.UpdateScript(ps, OldScriptCode, logI.Split('\\').LastOrDefault());
            }
            catch
            {
                ViewBag.OldScriptCode = OldScriptCode;
                return(View(ps));
            }
            return(RedirectToAction("Index"));
        }
        public ActionResult EditScript(string tId)
        {
            ActiveDirectoryWeb ad = new ActiveDirectoryWeb();

            string[] usr = ad.SearchActiveDirectory(HttpContext.User.Identity.Name).Split('|');
            ViewBag.IsAdmin = DataAccess.AdminAccess(usr[1]);

            PromoScript ps = new PromoScript();
            DataRow     dr = ScriptDataAccess.GetScript(tId);

            ps.ScriptTemplate     = dr["ScriptCode"].ToString();
            ps.ScriptName         = dr["ScriptName"].ToString();
            ps.BiScriptCode       = dr["BIScriptCode"].ToString();
            ps.CoreOfferSalesTax  = dr["CoreOfferSalesTax"].ToString();
            ps.CrossSalesTax      = dr["CrossSaleTax"].ToString();
            ps.Description        = dr["Description"].ToString();
            ps.BrandCode          = dr["BrandCode"].ToString();
            ViewBag.OldScriptCode = dr["ScriptCode"].ToString();
            ViewBag.BrandCode     = new SelectList(ScriptDataAccess.GetBrands(), "BrandCode", "BrandName", ps.BrandCode);
            return(View(ps));
        }
Beispiel #6
0
 public static void UpdateScript(PromoScript ps, string oldScriptCode, string userId)
 {
     using (SqlConnection scon = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLConn"].ConnectionString))
     {
         if (scon.State == ConnectionState.Closed)
         {
             scon.Open();
         }
         SqlCommand cmd = new SqlCommand();
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.Connection  = scon;
         cmd.CommandText = "usp_UpdateScript";
         cmd.Parameters.AddWithValue("@ScriptCode", ps.ScriptTemplate);
         cmd.Parameters.AddWithValue("@ScriptName", string.IsNullOrEmpty(ps.ScriptName) ? "" : ps.ScriptName);
         cmd.Parameters.AddWithValue("@BiScriptCode", string.IsNullOrEmpty(ps.BiScriptCode) ? "" : ps.BiScriptCode);
         cmd.Parameters.AddWithValue("@Description", string.IsNullOrEmpty(ps.Description) ? "" : ps.Description);
         cmd.Parameters.AddWithValue("@CoreOfferSalesTax", string.IsNullOrEmpty(ps.CoreOfferSalesTax) ? "" : ps.CoreOfferSalesTax);
         cmd.Parameters.AddWithValue("@CrossSaleTax", string.IsNullOrEmpty(ps.CrossSalesTax) ? "" : ps.CrossSalesTax);
         cmd.Parameters.AddWithValue("@BrandCode", string.IsNullOrEmpty(ps.BrandCode) ? "" : ps.BrandCode);
         cmd.Parameters.AddWithValue("@UserId", userId);
         cmd.Parameters.AddWithValue("@OldScriptCode", oldScriptCode);
         cmd.ExecuteNonQuery();
     }
 }