예제 #1
0
 //update
 public Tuple <string, int> AnimeDatabase_Update_Anime(AnimeDatabase_Anime newAnime)
 {
     using (var context = new ADContext())
     {
         context.Entry(newAnime).State = EntityState.Modified;
         return(new Tuple <string, int>(newAnime.AnimeName, context.SaveChanges()));
     }
 }
예제 #2
0
 //add new
 public Tuple <string, int> AnimeDatabase_Add_Anime(AnimeDatabase_Anime newAnime)
 {
     using (var context = new ADContext())
     {
         var newID = context.Anime.Add(newAnime);
         context.SaveChanges();
         return(new Tuple <string, int>(newAnime.AnimeName, newID.AnimeID));
     }
 }
예제 #3
0
    private AnimeDatabase_Anime CreateAnime()
    {
        AnimeDatabase_Anime newAnime = new AnimeDatabase_Anime();

        newAnime.AnimeName             = AnimeName.Text;
        newAnime.CurrentEpisode        = string.IsNullOrEmpty(CurrentlyOn.Text)? 0 : int.Parse(CurrentlyOn.Text);
        newAnime.TotalNumberOfEpisodes = string.IsNullOrEmpty(NumberOfEpisodes.Text) ? 0 : int.Parse(NumberOfEpisodes.Text);
        newAnime.NumberOfSeasons       = string.IsNullOrEmpty(NumberOfSeasons.Text) ? 0 : int.Parse(NumberOfSeasons.Text);
        newAnime.AnimeDescriptionID    = int.Parse(Rating.SelectedValue);
        return(newAnime);
    }
예제 #4
0
 protected void SubmitButton_Click(object sender, EventArgs e)
 {
     if (Page.IsValid)
     {
         if (Rating.SelectedIndex == 0)
         {
             Message.Text = "Invalid Rating. Please select a rating";
         }
         else
         {
             try
             {
                 AnimeDatabase_Anime newAnime = CreateAnime();
                 AnimeController     sysmgr   = new AnimeController();
                 Tuple <string, int> results  = sysmgr.AnimeDatabase_Add_Anime(newAnime);
                 Message.Text = "the anime '" + results.Item1 + "' has been sucessfully added with ID " + results.Item2.ToString();
             }
             catch (Exception ex)
             {
                 Message.Text = GetInnerException(ex).ToString();
             }
         }
     }
 }
    protected void Anime_GridView_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        #region Find Controls
        if (!string.IsNullOrEmpty(e.CommandName) && e.CommandName.ToUpper() != "PAGE")
        {
            //collect the row number / index number
            int index = Convert.ToInt32(e.CommandArgument);

            //this retreives the row itself...
            GridViewRow row = Anime_GridView.Rows[index];

            //this finds the control...
            var AnimeIDControl = (TextBox)row.FindControl("AnimeID");
            var AnimeNameControl = (TextBox)row.FindControl("AnimeName");
            var CurrentEpisodeControl = (TextBox)row.FindControl("CurrentEpisode");
            var NumberOfEpisodesControl = (TextBox)row.FindControl("EpisodeCount");
            var NumberOfSeasonsControl = (TextBox)row.FindControl("NumberOfSeasons");
            var DescriptionIDControl = (TextBox)row.FindControl("DescriptionID");
            var DescriptionTextBoxControl = (TextBox)row.FindControl("DescriptionTextBox");
            var DescriptionDropDownControl = (DropDownList)row.FindControl("DescriptionDropDownList");

            var EditButtonControl = (Button)row.FindControl("EditButton");
            var UpdateButtonControl = (Button)row.FindControl("UpdateButton");
            var DeleteButtonControl = (Button)row.FindControl("DeleteButton");
            var CancelButtonControl = (Button)row.FindControl("CancelButton");
            #endregion

            //allows editing to take place
            if (e.CommandName == "Edit Anime")
            {
                #region Edit Anime
                //allow editing...
                AnimeNameControl.ReadOnly = false;
                CurrentEpisodeControl.ReadOnly = false;
                NumberOfEpisodesControl.ReadOnly = false;
                NumberOfSeasonsControl.ReadOnly = false;

                //show / hide buttons and feilds...
                DescriptionTextBoxControl.Visible = false;
                DescriptionDropDownControl.Visible = true;

                EditButtonControl.Visible = false;
                UpdateButtonControl.Visible = true;
                DeleteButtonControl.Visible = false;
                CancelButtonControl.Visible = true;

                //setup drop down list...
                BindDescriptionsDDL_In_WebGrid(sender, e);
                #endregion

            }
            //delete the anime
            else if (e.CommandName == "Delete Anime")
            {
                #region Delete Anime

                if (string.IsNullOrEmpty(AnimeIDControl.Text))
                {
                    Message.Text = "Anime No Longer in existence, please select another anime.";
                    BindAnime();
                }
                try
                {
                    AnimeController sysmgr = new AnimeController();
                    var results = sysmgr.AnimeDatabase_Delete_Anime(int.Parse(AnimeIDControl.Text));
                    if (results.Item2 == 0)
                    {
                        Message.Text = "Delete Failed";
                    }
                    else
                    {
                        Message.Text = "the anime '" + results.Item1 + "' has been sucessfuly deleted";
                    }
                    BindAnime();

                }
                catch (Exception ex)
                {
                    Message.Text = GetInnerException(ex).ToString();
                }
                #endregion
            }
            //updates the anime
            else if (e.CommandName == "Save Changes")
            {
                #region Save changes / update Anime
                //stop editing...
                AnimeNameControl.ReadOnly = true;
                CurrentEpisodeControl.ReadOnly = true;
                NumberOfEpisodesControl.ReadOnly = true;
                NumberOfSeasonsControl.ReadOnly = true;

                //show / hide buttons and feilds...
                DescriptionTextBoxControl.Visible = true;
                DescriptionDropDownControl.Visible = false;

                EditButtonControl.Visible = true;
                UpdateButtonControl.Visible = false;
                DeleteButtonControl.Visible = true;
                CancelButtonControl.Visible = false;

                try
                {
                    AnimeDatabase_Anime UpdatedAnime = new AnimeDatabase_Anime();

                    #region Load Anime Data
                    UpdatedAnime.AnimeID = int.Parse(AnimeIDControl.Text);
                    UpdatedAnime.AnimeName = AnimeNameControl.Text;
                    UpdatedAnime.CurrentEpisode = string.IsNullOrEmpty(CurrentEpisodeControl.Text) ? 0 : int.Parse(CurrentEpisodeControl.Text);
                    UpdatedAnime.TotalNumberOfEpisodes = string.IsNullOrEmpty(NumberOfEpisodesControl.Text) ? 0 : int.Parse(NumberOfEpisodesControl.Text);
                    UpdatedAnime.NumberOfSeasons = string.IsNullOrEmpty(NumberOfSeasonsControl.Text) ? 0 : int.Parse(NumberOfSeasonsControl.Text);
                    UpdatedAnime.AnimeDescriptionID = int.Parse(DescriptionDropDownControl.SelectedValue);

                    #endregion

                    AnimeController sysmgr = new AnimeController();
                    var results = sysmgr.AnimeDatabase_Update_Anime(UpdatedAnime);
                    if (results.Item2 == 0)
                    {
                        Message.Text = "Update failed";
                    }
                    else
                    {
                        Message.Text = "the anime '" + results.Item1 + "' has been sucessfuly updated";
                    }
                    BindAnime();
                }
                catch (Exception ex)
                {
                    Message.Text = GetInnerException(ex).ToString();
                }
                #endregion
            }
            //resets the anime to before the changes
            else if (e.CommandName == "Cancel Changes")
            {
                #region cancel changes
                //allow editing...
                AnimeNameControl.ReadOnly = true;
                CurrentEpisodeControl.ReadOnly = true;
                NumberOfEpisodesControl.ReadOnly = true;
                NumberOfSeasonsControl.ReadOnly = true;

                //show / hide buttons and feilds...
                DescriptionTextBoxControl.Visible = true;
                DescriptionDropDownControl.Visible = false;

                EditButtonControl.Visible = true;
                UpdateButtonControl.Visible = false;
                DeleteButtonControl.Visible = true;
                CancelButtonControl.Visible = false;

                //reload data
                BindAnime();
                #endregion
            }

        }

    }