public string AddMusicDirector(string FirstName, string LastName)
        {
            if (ModelState.IsValid)
            {
                AdminAlbumDAL DalObj = new AdminAlbumDAL();
                AddAlbumMusicDirectorSongViewModel DirObject = new AddAlbumMusicDirectorSongViewModel();
                DirObject = DalObj.AddMusicDirectors(FirstName, LastName);
                if (DirObject.MusicDirctorID != -1)
                {
                    ViewBag.Message = "DirectorId" + DirObject.MusicDirctorID;

                }
                else
                {
                    ViewBag.Messgae = "-1";
                }
                return DirObject.MusicDirctorID.ToString();

            }
            return "false";
        }
Ejemplo n.º 2
0
        public AddAlbumMusicDirectorSongViewModel AddMusicDirectors(string FirstName, string LastName)
        {
            //bool status = false;
            string conStr = ConfigurationManager.ConnectionStrings["ConnectToStopNShopDatabase"].ConnectionString;
            SqlConnection conn = new SqlConnection(conStr);
            AddAlbumMusicDirectorSongViewModel DirObj = null;
            try
            {
                conn.Open();

                SqlCommand check = new SqlCommand("select count(*) from MusicDirectors where FirstName=@firstname and LastName=@lastname", conn);
                check.Parameters.AddWithValue("firstname", FirstName);
                check.Parameters.AddWithValue("lastname", LastName);

                int num = (int)check.ExecuteScalar();

                if (num == 0)
                {
                    SqlCommand cmd = new SqlCommand("insert into MusicDirectors values (@firstname,@lastname)", conn);
                    cmd.Parameters.AddWithValue("firstname", FirstName);
                    cmd.Parameters.AddWithValue("lastname", LastName);
                    int res = cmd.ExecuteNonQuery();
                    //status = true;
                    SqlCommand id = new SqlCommand("select Id,FirstName,LastName from MusicDirectors where FirstName=@firstname and LastName=@lastname", conn);
                    id.Parameters.AddWithValue("firstname", FirstName);
                    id.Parameters.AddWithValue("lastname", LastName);
                    var reader = id.ExecuteReader();
                    if (reader.HasRows)
                    {
                        reader.Read();
                        DirObj = new AddAlbumMusicDirectorSongViewModel();
                        DirObj.MusicDirctorID = reader.GetInt32(reader.GetOrdinal("Id"));
                        DirObj.DataError = null;
                    }
                }
                else
                {
                    DirObj = new AddAlbumMusicDirectorSongViewModel();
                    DirObj.MusicDirctorID = -1;
                }
            }
            catch (Exception exc)
            {
                HttpContext.Current.Session["ErrorMessage"] = exc.Message;
            }
            conn.Close();
            return DirObj;
        }