public async Task <string> CreateAsync(string storyId, IEnumerable <string> categoryIds) { var story = await this.dbContext .Stories .Where(s => s.Id == storyId && !s.IsDeleted) .FirstOrDefaultAsync(); if (story == null) { return(StoryErrors.NotFoundOrDeletedStory); } foreach (var id in categoryIds) { var storyCategory = new StoryCategories { StoryId = story.Id, CategoryId = id }; await this.dbContext.StoryCategories.AddAsync(storyCategory); } await this.dbContext.SaveChangesAsync(); return(story.Id); }
protected void Save_Click(Object sender, EventArgs e) { StoryCategories _cat = new StoryCategories(this.ConnectionString); _cat.Description = txt_Description.Text; if (!_cat.Save()) { lbl_Error.Text = "An unexpected error has occurred. Please try again."; } else { lbl_Error.Text = ""; txt_Description.Text = ""; BindData(); } }
protected void Category_OnUpdateCommand(Object sender, DataGridCommandEventArgs e) { StoryCategories _cat = new StoryCategories(this.ConnectionString); String _id = dg_category.DataKeys[e.Item.ItemIndex].ToString(); _cat.ID = _id; _cat.Description = ((TextBox)e.Item.FindControl("txt_Desc")).Text; _cat.Sort = Convert.ToInt32(((TextBox)e.Item.FindControl("txt_Sort")).Text); if (!_cat.Save()) { lbl_Error.Text = "An unexpected error has occurred. Please try again."; } else { lbl_Error.Text = ""; dg_category.EditItemIndex = -1; val_Desc.Enabled = true; BindData(); } }