Exemplo n.º 1
0
        public String AddLibrarian(LibraryLibrarian librarian)
        {
            if (!librarian.IsValid(librarian.EmailID)) { return "Not valid Email ID"; }
            try
            {
                SqlConnection conn = null;

                conn = new SqlConnection(@"Data Source = (LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\LMS_DB.mdf;Integrated Security = True");
                conn.Open();
                SqlCommand cmd = new SqlCommand("dbo.Administrator_AddLibrarian", conn);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add("@email_id", SqlDbType.NVarChar).Value = librarian.EmailID;
                cmd.Parameters.Add("@password", SqlDbType.NVarChar).Value = librarian.Password;
                cmd.Parameters.Add("@firstname", SqlDbType.NVarChar).Value = librarian.FirstName;
                cmd.Parameters.Add("@lastname", SqlDbType.NVarChar).Value = librarian.LastName;

                cmd.ExecuteNonQuery();
                return "Successfully added the librarian.";
            }
            catch (SqlException sqlEx)
            {
                if (sqlEx.Message.StartsWith("Violation of UNIQUE KEY constraint"))
                {
                    return "Duplicate Email_ID. Check again.";
                }
                else
                    throw;
            }
        }
Exemplo n.º 2
0
        public String DeleteLibrarian(LibraryLibrarian librarian)
        {
            if (!librarian.IsValid(librarian.EmailID)) { return "Not valid Email ID"; }

            SqlConnection conn = null;

            conn = new SqlConnection(@"Data Source = (LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\LMS_DB.mdf;Integrated Security = True");
            conn.Open();
            SqlCommand cmd = new SqlCommand("dbo.Administrator_DeleteLibrarian", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@Id", SqlDbType.NVarChar).Value = librarian.Id;

            cmd.ExecuteNonQuery();
            return "Successfully Deleted the librarian.";
        }