コード例 #1
0
        public void Delete(NationalityEntity t)
        {
            SqlConnection conn = null;
            SqlCommand    cmd  = null;

            try
            {
                conn            = DALHelper.CreateSqlDbConnection();
                cmd             = new SqlCommand("usp_DeleteNationality", conn);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@Id", t.Id);

                cmd.ExecuteNonQuery();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                conn.Close();
                cmd.Dispose();
                conn.Dispose();
            }
        }
コード例 #2
0
        public void Update(NationalityEntity t)
        {
            SqlConnection conn = null;
            SqlCommand    cmd  = null;

            try
            {
                conn            = DALHelper.CreateSqlDbConnection();
                cmd             = new SqlCommand("usp_UpdateNationality", conn);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@Id", t.Id);
                cmd.Parameters.AddWithValue("@Title", t.Title);
                cmd.Parameters.AddWithValue("@Description", t.Description);
                cmd.Parameters.AddWithValue("@Status", Convert.ToInt32(t.Status));

                cmd.ExecuteNonQuery();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                conn.Close();
                cmd.Dispose();
                conn.Dispose();
            }
        }
コード例 #3
0
        public void Insert(NationalityEntity t)
        {
            SqlConnection conn = null;
            SqlCommand    cmd  = null;

            try
            {
                conn            = DALHelper.CreateSqlDbConnection();
                cmd             = new SqlCommand("usp_InsertNationality", conn);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@Title", t.Title);
                cmd.Parameters.AddWithValue("@Description", t.Description);

                t.Id = Convert.ToInt32(cmd.ExecuteScalar());
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                conn.Close();
                cmd.Dispose();
                conn.Dispose();
            }
        }
コード例 #4
0
ファイル: Add.aspx.cs プロジェクト: apkalexei/HRMS
        protected void ProceedButton_Click(object sender, EventArgs e)
        {
            NationalityEntity entity = new NationalityEntity();

            entity.Title       = TitleTextBox.Text;
            entity.Description = OtherInfoTextBox.Text;

            new NationalityMapper().Insert(entity);
            Response.Redirect("List.aspx");
        }
コード例 #5
0
        protected void ProceedButton_Click(object sender, EventArgs e)
        {
            NationalityEntity entity = new NationalityEntity();

            entity.Id          = Convert.ToInt32(Request.QueryString["NationalityId"]);
            entity.Title       = TitleTextBox.Text;
            entity.Description = OtherInfoTextBox.Text;
            entity.Status      = StatusEnum.Active;

            new NationalityMapper().Update(entity);

            Response.Redirect("List.aspx");
        }
コード例 #6
0
        private int GetNationalityId(string name)
        {
            NationalityEntity ent = _context.Nationalities.FirstOrDefault(n => n.Name == name);

            if (ent == null)
            {
                ent = new NationalityEntity()
                {
                    Name      = name,
                    ShortName = name.Substring(0, 3).ToUpper(),
                };
                _context.Nationalities.Add(ent);
                _context.SaveChanges();
            }
            return(ent.NationalityId);
        }
コード例 #7
0
        public List <NationalityEntity> List(string search)
        {
            SqlConnection conn = null;
            SqlCommand    cmd  = null;

            try
            {
                conn            = DALHelper.CreateSqlDbConnection();
                cmd             = new SqlCommand("usp_ListNationalities", conn);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@Search", search);

                SqlDataReader            rdr  = cmd.ExecuteReader();
                List <NationalityEntity> list = new List <NationalityEntity>();

                while (rdr.Read())
                {
                    NationalityEntity entity = new NationalityEntity();
                    entity.Id     = Convert.ToInt32(rdr["Id"]);
                    entity.Status = (StatusEnum)rdr["Status"];
                    entity.Title  = Convert.ToString(rdr["Title"]);

                    list.Add(entity);
                }

                return(list);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                conn.Close();
                cmd.Dispose();
                conn.Dispose();
            }
        }
コード例 #8
0
        public NationalityEntity Get(NationalityEntity t)
        {
            SqlConnection conn = null;
            SqlCommand    cmd  = null;

            try
            {
                conn            = DALHelper.CreateSqlDbConnection();
                cmd             = new SqlCommand("usp_GetNationalityById", conn);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@Id", t.Id);

                SqlDataReader     rdr    = cmd.ExecuteReader();
                NationalityEntity entity = new NationalityEntity();

                while (rdr.Read())
                {
                    entity.Id          = Convert.ToInt32(rdr["Id"]);
                    entity.Status      = (StatusEnum)Convert.ToInt32(rdr["Status"]);
                    entity.Title       = Convert.ToString(rdr["Title"]);
                    entity.Description = Convert.ToString(rdr["Description"]);
                }

                return(entity);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                conn.Close();
                cmd.Dispose();
                conn.Dispose();
            }
        }