public async Task <Result <Guid> > Handle(CreateTagCommand request, CancellationToken token) { using (var transaction = await _context.BeginTransactionAsync(token)) { var entity = new Domain.Tag(Guid.NewGuid(), request.Kind, request.Name, request.Description, request.Picture); entity.SetAvailable(request.Available); await _context.AddAsync(entity, token); await _context.SaveChangesAsync(token); var imageResult = await _mediatr.Process(new UpdateTagPictureCommand(request.RequestUser) { TagId = entity.Id, Picture = request.Picture }, token); if (!imageResult.Succeeded) { return(Failure <Guid>(imageResult)); } var iconResult = await _mediatr.Process(new UpdateTagIconCommand(request.RequestUser) { TagId = entity.Id, Icon = request.Icon }, token); if (!iconResult.Succeeded) { return(Failure <Guid>(iconResult)); } await transaction.CommitAsync(token); return(Success(entity.Id)); } }
public void Execute(AddTag request) { _validator.ValidateAndThrow(request); var tag = new Domain.Tag { Content = request.Content, CreatedAt = DateTime.Now, ModifidedAt = null, IsDeleted = false }; if (Context.Tag.Any(t => t.Content == request.Content)) { throw new EntityAllreadyExists("Tag"); } Context.Tag.Add(tag); try { Context.SaveChanges(); } catch (Exception) { throw new Exception(); } }
public async Task <Domain.Tag> Save(Model model) { var tool = db.Tags.SingleOrDefault(s => s.Name.ToLower() == model.Name.ToLower() && s.TagType == Domain.TagType.Tool); if (tool != null) { if (tool.DeletedAt != null) { tool.DeletedAt = null; await db.SaveChangesAsync(); } return(tool); } tool = new Domain.Tag { Name = model.Name, TagType = Domain.TagType.Tool }; db.Tags.Add(tool); await db.SaveChangesAsync(); return(tool); }
public async Task <Domain.Tag> Save(Model model) { var tag = db.Tags.SingleOrDefault(s => s.Name.ToLower() == model.Name.ToLower() && s.TagType == Domain.TagType.Normal); if (tag != null) { if (tag.DeletedAt != null) { tag.DeletedAt = null; await db.SaveChangesAsync(); } return(tag); } tag = new Domain.Tag { Name = model.Name, TagType = Domain.TagType.Normal }; db.Tags.Add(tag); await db.SaveChangesAsync(); return(new Domain.Tag { Id = tag.Id, Name = tag.Name, TagType = tag.TagType }); }
public static async Task <IEnumerable <Domain.Tag> > SaveTagsAsync(this SampleExamContext context, IEnumerable <string> tagList, CancellationToken cancellationToken) { var tags = new List <Domain.Tag>(); foreach (var tag in tagList) { var t = await context.Tags.FindAsync(tag); if (t == null) { t = new Domain.Tag() { TagId = tag }; await context.Tags.AddAsync(t, cancellationToken); await context.SaveChangesAsync(cancellationToken); } tags.Add(t); } return(tags); }
public static Database.Tagging.Tag ToDatabaseModel(Domain.Tag d) { if (d == null) { return(null); } return(new Database.Tagging.Tag { Id = d.Id, Name = d.Name, Description = d.Description, ItemTags = new List <Database.Tagging.ItemTag>(), PantryItemTags = new List <Database.Tagging.PantryItemTag>(), RecipeTags = new List <Database.Tagging.RecipeTag>() }); }
public async Task Handle(Command message) { var tag = await db.Tag.SingleOrDefaultAsync(t => t.Nome == message.Nome); if (tag == null) { tag = new Domain.Tag { Nome = message.Nome }; db.Tag.Add(tag); } var publication_tag = new Domain.Publication_Tag { PublicationId = message.PublicationId, TagId = tag.Id }; db.Publication_Tag.Add(publication_tag); }
public async Task <IActionResult> Create([FromBody] TagCreateRequest request) { var tag = new Domain.Tag { Name = request.TagName, CreatorId = this.HttpContext.GetUserId(), CreatedOn = DateTime.UtcNow }; var isCreated = await this.postService.CreateTagAsync(tag); if (!isCreated) { var errorResponse = new ErrorResponse(); errorResponse.Errors.Add(new ErrorModel { Message = "Unable to create tag" }); return(this.BadRequest(errorResponse)); } var baseUrl = $"{this.HttpContext.Request.Scheme}://{this.HttpContext.Request.Host.ToUriComponent()}"; var locationUri = baseUrl + "/" + ApiRoutes.Tags.Get.Replace("{tagName}", tag.Name); return(this.Created(locationUri, this.mapper.Map <TagResponse>(tag))); }
private void btnAddTag_Click(object sender, RoutedEventArgs e) { if (acbTag.Text != "") { Domain.Tag tag = new Domain.Tag(); tag.Name = acbTag.Text; TempVisitTags.Add(tag); lbxTags.ItemsSource = null; lbxTags.ItemsSource = TempVisitTags; acbTag.Text = ""; } }
protected override void Seed(TomasHorvath.BlogEngine.DAL.BlogEngineDbContext db) { // clear all data db.Database.ExecuteSqlCommand("sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'"); db.Database.ExecuteSqlCommand("sp_MSForEachTable 'IF OBJECT_ID(''?'') NOT IN (ISNULL(OBJECT_ID(''[dbo].[__MigrationHistory]''),0)) DELETE FROM ?'"); db.Database.ExecuteSqlCommand("EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'"); var roleStore = new RoleStore <IdentityRole>(db); var roleManager = new RoleManager <IdentityRole>(roleStore); var userStore = new UserStore <Domain.Author>(db); var userManager = new UserManager <Domain.Author>(userStore); if (!db.Users.Any()) { var role = roleManager.FindByName("Admin"); if (role == null) { role = new IdentityRole("Admin"); roleManager.Create(role); } // Create test users var user = userManager.FindByName("admin"); if (user == null) { var newUser = new Domain.Author() { UserName = "******", FirstName = "Admin", LastName = "User", Email = "*****@*****.**", PhoneNumber = "602162083" }; userManager.Create(newUser, "Password1"); userManager.SetLockoutEnabled(newUser.Id, false); userManager.AddToRole(newUser.Id, "Admin"); } } var author = userManager.FindByName("admin"); var blogPost = new Domain.BlogPost() { Author = author, AuthorId = author.Id, Content = "Hello world", DateOfChange = DateTime.Now, DateOfCreated = DateTime.Now, DateOfPublished = DateTime.Now, Description = "popis", Keyword = "SEO keywords", Headline = "New blog post", Perex = "Short blog post description lorem impsum" }; var blogPost2 = new Domain.BlogPost() { Author = author, AuthorId = author.Id, Content = "Hello world1", DateOfChange = DateTime.Now, DateOfCreated = DateTime.Now, DateOfPublished = DateTime.Now, Description = "popis", Keyword = "SEO keywords", Headline = "New blog post1", Perex = "Short blog post description lorem impsum 1" }; var blogPost3 = new Domain.BlogPost() { Author = author, AuthorId = author.Id, Content = "Hello world", DateOfChange = DateTime.Now, DateOfCreated = DateTime.Now, DateOfPublished = DateTime.Now, Description = "popis", Keyword = "SEO keywords", Headline = "New blog post", Perex = "Just test " }; var slug = new Domain.Slug() { EntityId = blogPost.Id, EntityType = Domain.EntityType.BlogPost, Url = "hello-world" }; var slug2 = new Domain.Slug() { EntityId = blogPost2.Id, EntityType = Domain.EntityType.BlogPost, Url = "blogpost1" }; var slug3 = new Domain.Slug() { EntityId = blogPost3.Id, EntityType = Domain.EntityType.BlogPost, Url = "some-url" }; var tag = new Domain.Tag() { BlogPostId = blogPost.Id, TagName = "Test" }; // page var page = new Domain.Page(); page.Author = author; page.AuthorId = author.Id; page.Keyword = "kez"; page.Name = "Contact"; page.IsContantPage = true; page.Headline = "Kontaktni informace"; page.Description = "Popis"; page.DisplayOrder = 1; page.Content = "obsah"; page.DateOfChange = DateTime.Now; page.DateOfCreated = DateTime.Now; page.DateOfPublished = DateTime.Now; var kontaktPageUrl = new Domain.Slug(); kontaktPageUrl.EntityId = page.Id; kontaktPageUrl.Url = "kontakt"; kontaktPageUrl.EntityType = Domain.EntityType.Page; var about = new Domain.Page(); about.Author = author; about.AuthorId = author.Id; about.Keyword = "kez"; about.Name = "O nás"; about.IsContantPage = true; about.Headline = "Kontaktni informace"; about.Description = "Popis"; about.DisplayOrder = 1; about.Content = "obsah"; about.DateOfChange = DateTime.Now; about.DateOfCreated = DateTime.Now; about.DateOfPublished = DateTime.Now; var aboutPageUrl = new Domain.Slug(); aboutPageUrl.EntityId = about.Id; aboutPageUrl.Url = "o-nas"; aboutPageUrl.EntityType = Domain.EntityType.Page; db.Pages.Add(page); db.Pages.Add(about); db.Slugs.Add(aboutPageUrl); db.Slugs.Add(kontaktPageUrl); // settings string type = ""; var blogName = new Domain.BlogSettings(); blogName.Key = "BlogName"; blogName.Value = "Simplycity is key"; blogName.DataType = type.GetType().ToString(); var blogMotto = new Domain.BlogSettings(); blogMotto.Key = "BlogMotto"; blogMotto.Value = "subheadline motto text"; blogMotto.DataType = type.GetType().ToString(); var BrandName = new Domain.BlogSettings(); BrandName.Key = "BrandName"; BrandName.Value = "BlogEngine"; BrandName.DataType = type.GetType().ToString(); db.Settings.Add(BrandName); db.Settings.Add(blogMotto); db.Settings.Add(blogName); blogPost.Tags.Add(tag); db.BlogPosts.Add(blogPost); db.BlogPosts.Add(blogPost2); db.BlogPosts.Add(blogPost3); db.Slugs.Add(slug); db.Slugs.Add(slug2); db.Slugs.Add(slug3); }
public static void InitializeIdentityForEF(BlogEngineDbContext db) { var roleStore = new RoleStore <IdentityRole>(db); var roleManager = new RoleManager <IdentityRole>(roleStore); var userStore = new UserStore <Domain.Author>(db); var userManager = new UserManager <Domain.Author>(userStore); if (!db.Users.Any()) { var role = roleManager.FindByName("Admin"); if (role == null) { role = new IdentityRole("Admin"); roleManager.Create(role); } // Create test users var user = userManager.FindByName("admin"); if (user == null) { var newUser = new Domain.Author() { UserName = "******", FirstName = "Admin", LastName = "User", Email = "*****@*****.**", PhoneNumber = "602162083" }; userManager.Create(newUser, "Password1"); userManager.SetLockoutEnabled(newUser.Id, false); userManager.AddToRole(newUser.Id, "Admin"); } } var author = userManager.FindByName("admin"); var blogPost = new Domain.BlogPost() { Author = author, AuthorId = author.Id, Content = "Hello world", DateOfChange = DateTime.Now, DateOfCreated = DateTime.Now, DateOfPublished = DateTime.Now, Description = "popis", Keyword = "SEO keywords", Headline = "New blog post", Perex = "Short blog post description lorem impsum" }; var blogPost2 = new Domain.BlogPost() { Author = author, AuthorId = author.Id, Content = "Hello world1", DateOfChange = DateTime.Now, DateOfCreated = DateTime.Now, DateOfPublished = DateTime.Now, Description = "popis", Keyword = "SEO keywords", Headline = "New blog post1", Perex = "Short blog post description lorem impsum 1" }; var blogPost3 = new Domain.BlogPost() { Author = author, AuthorId = author.Id, Content = "Hello world", DateOfChange = DateTime.Now, DateOfCreated = DateTime.Now, DateOfPublished = DateTime.Now, Description = "popis", Keyword = "SEO keywords", Headline = "New blog post", Perex = "Just test " }; var slug = new Domain.Slug() { EntityId = blogPost.Id, EntityType = Domain.EntityType.BlogPost, Url = "hello-world" }; var slug2 = new Domain.Slug() { EntityId = blogPost2.Id, EntityType = Domain.EntityType.BlogPost, Url = "blogpost1" }; var slug3 = new Domain.Slug() { EntityId = blogPost3.Id, EntityType = Domain.EntityType.BlogPost, Url = "some-url" }; var tag = new Domain.Tag() { BlogPostId = blogPost.Id, TagName = "Test" }; // page //var page = new Domain.Page(); //page.Author = author; //page.AuthorId = author.Id; //page.Keyword = "kez"; //page.Name = "Kontakt"; //page.IsContantPage = true; //page.Headline = "Kontaktni informace"; //page.Description = "Popis"; //page.DisplayOrder = 1; //page.Content = "obsah"; //page.DateOfChange = DateTime.Now; //page.DateOfCreated = DateTime.Now; //page.DateOfPublished = DateTime.Now; //var kontaktPageUrl = new Domain.Slug(); //kontaktPageUrl.EntityId = page.Id; //kontaktPageUrl.Url = "kontakt"; //kontaktPageUrl.EntityType = Domain.EntityType.Page; //var about = new Domain.Page(); //about.Author = author; //about.AuthorId = author.Id; //about.Keyword = "kez"; //about.Name = "Kontakt"; //about.IsContantPage = true; //about.Headline = "Kontaktni informace"; //about.Description = "Popis"; //about.DisplayOrder = 1; //about.Content = "obsah"; //about.DateOfChange = DateTime.Now; //about.DateOfCreated = DateTime.Now; //about.DateOfPublished = DateTime.Now; //var aboutPageUrl = new Domain.Slug(); //aboutPageUrl.EntityId = page.Id; //aboutPageUrl.Url = "o-nas"; //aboutPageUrl.EntityType = Domain.EntityType.Page; //db.Pages.Add(page); //db.Pages.Add(about); //db.Slugs.Add(aboutPageUrl); //db.Slugs.Add(kontaktPageUrl); // settings string type = ""; var blogName = new Domain.BlogSettings(); blogName.Key = "BlogName"; blogName.Value = "Simplycity is key"; blogName.DataType = type.GetType().ToString(); var blogMotto = new Domain.BlogSettings(); blogMotto.Key = "BlogMotto"; blogMotto.Value = "subheadline motto text"; blogMotto.DataType = type.GetType().ToString(); var BrandName = new Domain.BlogSettings(); BrandName.Key = "BrandName"; BrandName.Value = "BlogEngine"; BrandName.DataType = type.GetType().ToString(); db.Settings.Add(BrandName); db.Settings.Add(blogMotto); db.Settings.Add(blogName); blogPost.Tags.Add(tag); db.BlogPosts.Add(blogPost); db.BlogPosts.Add(blogPost2); db.BlogPosts.Add(blogPost3); db.Slugs.Add(slug); db.Slugs.Add(slug2); db.Slugs.Add(slug3); }