private static bool Operation1() { var biz = new CategoryDAO(ConfigHelper.GetConnString("test")); try { TransactionOptions option = new TransactionOptions(); option.IsolationLevel = IsolationLevel.ReadUncommitted; using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, option)) { Category cate = new Category(); cate.Code = "test3"; cate.DbName = "test3"; int id = biz.InsertWithId(cate); cate.Code = "test4";//"TCPKData_NingX"; cate.DbName = "test4"; biz.Insert(cate); scope.Complete(); } return true; } catch (Exception ex) { Console.WriteLine(ex.ToString()); return false; } }
public ActionResult Create(Category category) { if (ModelState.IsValid) { db.Category.Add(category); db.SaveChanges(); return RedirectToAction("Index"); } return View(category); }
protected void InserCategoriesButton_Click(object sender, EventArgs e) { Category category = new Category() { Name = string.IsNullOrEmpty(this.InsertCategoryNameTextBox.Text) ? "NoName" : this.InsertCategoryNameTextBox.Text }; this.db.Categories.Add(category); db.SaveChanges(); }
public async Task <CategoryDto> Create(Guid userId, CategoryForCreationDto categoryForCreationDto) { var category = new Data.Category() { Name = categoryForCreationDto.Name, Description = categoryForCreationDto.Description, CreatedBy = userId }; category = await _categoryRepositoryRepository.Add(category); await _categoryRepositoryRepository.CommitAsync(); return(_mapper.Map <Data.Category, CategoryDto>(category)); }
public EssayViewModel(Essay essay, Category essayCategory) { Essay = essay; CurrentCategory = essayCategory; var essayIndex = CurrentCategory.EssaysForCategory.FindIndex(e => e.Title == essay.Title); if (essayIndex < CurrentCategory.EssaysForCategory.Count - 1) { NextEssayForCategory = CurrentCategory.EssaysForCategory[essayIndex + 1]; } else { NextEssayForCategory = CurrentCategory.EssaysForCategory[0]; } SiteTitle = essay.Title; }
public void Update(Category category) { shoppingCardDB.Entry(category).State = EntityState.Modified; Save(); }
public void Create(Category category) { shoppingCardDB.Categories.Add(category); Save(); }
partial void DeleteCategory(Category instance);
partial void UpdateCategory(Category instance);
partial void InsertCategory(Category instance);
public IHttpActionResult PostBook(BookPostBindingModel newBook) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var book = new Book() { Title = newBook.Title, Description = newBook.Description, Price = newBook.Price, Copies = newBook.Copies, EditionType = newBook.EditionType, AgeRestriction = newBook.AgeRestriction, ReleaseDate = newBook.ReleaseDate, AuthorId = newBook.AuhtorId, }; foreach (var category in newBook.Categories) { if (_db.Categories.Any(c => c.Name == category)) { book.Categories.Add(_db.Categories.FirstOrDefault(c => c.Name == category)); } else { var newCategory = new Category(); newCategory.Name = category; book.Categories.Add(newCategory); } } _db.Books.Add(book); _db.SaveChanges(); return this.Ok(new { id = book.Id, isCreated = true }); }
public void Add(Category category) { this.categories.Add(category); }
protected override void Seed(BlogContext context) { //// // This Seed method will be run everytime we run build command. Be careful as database // will be dropped and data regenerated (use this during development or testing, NOT in production) //// // We add a contributor and an administrator for being able to enter the application User adminUser = context.Users.Add( new User { Email = "*****@*****.**", Password = "******", // Password: admin Role = UserRoles.Administrator, Profile = "This is the administrator for the blog", ImagePath = "user_1.png" }); User contributorUser = context.Users.Add( new User { Email = "*****@*****.**", Password = "******", // Password: contributor Role = UserRoles.Contributor, Profile = "This is the contributor for the blog", ImagePath = "user_2.png" } ); // We add some static pages in the application StaticPage page1 = context.StaticPages.Add( new StaticPage { Title = "First page", Content = GetLipsum(4) } ); StaticPage page2 = context.StaticPages.Add( new StaticPage { Title = "Second page", Content = GetLipsum(4) } ); // We add some categories to start using application Category programmingCategory = context.Categories.Add( new Category { Name = "Programming languages" } ); Category managementCategory = context.Categories.Add( new Category { Name = "Management techniques" } ); Category databaseCategory = context.Categories.Add( new Category { Name = "Databases" } ); // We add some tags to start using application Tag aspnetTag = context.Tags.Add( new Tag { Name = "ASP.NET" } ); Tag nodejsTag = context.Tags.Add( new Tag { Name = "NodeJS" } ); Tag apiTag = context.Tags.Add( new Tag { Name = "API" } ); Tag mvc5Tag = context.Tags.Add( new Tag { Name = "MVC 5" } ); Tag javascriptTag = context.Tags.Add( new Tag { Name = "Javascript" } ); // We add some posts to start using application Post post1 = context.Posts.Add( new Post { Title = "First post", Content = GetLipsum(), User = adminUser, Category = managementCategory, Tags = new List <Tag>() { aspnetTag, mvc5Tag, javascriptTag }, Visible = true, AddedOn = DateTime.Today, ModifiedOn = DateTime.Today, Attachments = new List <Attachment>() { new Attachment() { Name = "First attachment", Path = "Seeded_file_1.txt", Size = 13 }, new Attachment() { Name = "Second attachment", Path = "Seeded_file_2.txt", Size = 13 } } } ); PostComment comment1_1 = context.PostComments.Add(new PostComment { Content = GetLipsum(1, false), AuthorEmail = "*****@*****.**", AddedOn = DateTime.Today, Post = post1 }); PostComment comment1_2 = context.PostComments.Add(new PostComment { Content = GetLipsum(1, false), User = contributorUser, AddedOn = DateTime.Today, Post = post1 }); PostComment comment1_3 = context.PostComments.Add(new PostComment { Content = GetLipsum(1, false), User = contributorUser, AddedOn = DateTime.Today, Post = post1 }); PostComment comment1_1_1 = context.PostComments.Add(new PostComment { Content = GetLipsum(1, false), User = contributorUser, AddedOn = DateTime.Today, Post = post1, ParentPostComment = comment1_1 }); PostComment comment1_1_2 = context.PostComments.Add(new PostComment { Content = GetLipsum(1, false), AuthorEmail = "*****@*****.**", AddedOn = DateTime.Today, Post = post1, ParentPostComment = comment1_1 }); PostComment comment1_3_1 = context.PostComments.Add(new PostComment { Content = GetLipsum(1, false), AuthorEmail = "*****@*****.**", AddedOn = DateTime.Today, Post = post1, ParentPostComment = comment1_3 }); Post post2 = context.Posts.Add( new Post { Title = "Second post", Content = GetLipsum(), User = adminUser, Category = programmingCategory, Tags = new List <Tag>() { aspnetTag, mvc5Tag }, Visible = false, AddedOn = DateTime.Today, ModifiedOn = DateTime.Today } ); PostComment comment2_1 = context.PostComments.Add(new PostComment { Content = GetLipsum(1, false), AuthorEmail = "*****@*****.**", AddedOn = DateTime.Today, Post = post2 }); PostComment comment2_2 = context.PostComments.Add(new PostComment { Content = GetLipsum(1, false), User = contributorUser, AddedOn = DateTime.Today, Post = post2 }); PostComment comment2_3 = context.PostComments.Add(new PostComment { Content = GetLipsum(1, false), User = contributorUser, AddedOn = DateTime.Today, Post = post2 }); PostComment comment2_1_1 = context.PostComments.Add(new PostComment { Content = GetLipsum(1, false), User = contributorUser, AddedOn = DateTime.Today, Post = post2, ParentPostComment = comment2_1 }); PostComment comment2_1_2 = context.PostComments.Add(new PostComment { Content = GetLipsum(1, false), AuthorEmail = "*****@*****.**", AddedOn = DateTime.Today, Post = post2, ParentPostComment = comment2_1 }); PostComment comment2_3_1 = context.PostComments.Add(new PostComment { Content = GetLipsum(1, false), AuthorEmail = "*****@*****.**", AddedOn = DateTime.Today, Post = post2, ParentPostComment = comment2_3 }); Post post3 = context.Posts.Add( new Post { Title = "Third post", Content = GetLipsum(), User = contributorUser, Category = databaseCategory, Tags = new List <Tag>() { nodejsTag, javascriptTag, apiTag }, Visible = true, AddedOn = DateTime.Today, ModifiedOn = DateTime.Today } ); PostComment comment3_1 = context.PostComments.Add(new PostComment { Content = GetLipsum(1, false), AuthorEmail = "*****@*****.**", AddedOn = DateTime.Today, Post = post3 }); PostComment comment3_2 = context.PostComments.Add(new PostComment { Content = GetLipsum(1, false), User = contributorUser, AddedOn = DateTime.Today, Post = post3 }); context.SaveChanges(); base.Seed(context); }
public ActionResult Edit(Category category) { if (ModelState.IsValid) { db.Entry(category).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(category); }
protected void Dispose() { this._category = null; }
protected void Setup() { this._category = new Category(ConfigurationManager.ConnectionStrings["lightframework"].ConnectionString); }