Ejemplo n.º 1
0
        public bool AddnewDepartment(Cms_Department cmsdepartment)
        {
            string departmentname, regdate;

            try
            {
                con.Open();
                SqlTransaction trans = con.BeginTransaction();

                try
                {
                    departmentname = cmsdepartment.Cms_Departmentname;
                    regdate        = cmsdepartment.Cms_Departmentregister.ToString();
                    SqlCommand dbcmd = con.CreateCommand();
                    dbcmd.Transaction = trans;
                    dbcmd.CommandText = "insert into Cms_Department(Cms_Departmentname,Cms_Departmentregister) Values(@departmentname,@regdate)";
                    dbcmd.Parameters.AddWithValue("@departmentname", departmentname);
                    dbcmd.Parameters.AddWithValue("@regdate", regdate);
                    dbcmd.ExecuteNonQuery();
                    trans.Commit();
                    con.Close();
                    return(true);
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    con.Close();
                    return(false);
                }
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        public string Checkexist_department(Cms_Department cmsuser)
        {
            string department;

            department = cmsuser.Cms_Departmentname;
            SqlCommand cmd = con.CreateCommand();

            cmd.CommandText = "Select * from Cms_Department Where Cms_Departmentname=@department";
            cmd.Parameters.AddWithValue("@department", department);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet        ds = new DataSet();

            con.Open();
            da.Fill(ds);
            con.Close();

            if (ds.Tables[0].Rows.Count != 0)
            {
                return("Department already exists");
            }

            return("Added succeess fully");
        }
Ejemplo n.º 3
0
 public ActionResult Adddepartment(Cms_Department cms_department)
 {
     if (ModelState.IsValid)
     {
         cms_department.Cms_Departmentregister = Convert.ToDateTime(DateTime.Now.ToLongTimeString());
         string a = qh.Checkexist_department(cms_department);
         if (a == "Department already exists")
         {
             ViewBag.message = "Department name is already exists";
         }
         else
         {
             qh.AddnewDepartment(cms_department);
             ModelState.Clear();
         }
     }
     else
     {
         ViewBag.Error = "Something went wrong";
     }
     ViewBag.Success = "Successfully register for Cms system!! ";
     return(View());
 }