public static Category Map(Domain.Models.Category model) { return(new Category { Id = model.ID, Name = model.Name }); }
public static CategoryModel Map(Domain.Models.Category category) { return(new CategoryModel { ID = category.ID, Name = category.Name }); }
public async Task <IActionResult> Post([FromBody] Domain.Models.Category category) { await _categoryService.AddAsync(category); return(Created($"/api/category/{category.Id}", new Domain.Models.Category { Id = category.Id })); }
public ICategory Add(Domain.Models.Category entity) { var sEntity = entity.ToPersistentEntity(); var insertedRow = context.Categories.Add(sEntity); context.SaveChanges(); return(insertedRow.ToDomainEntity()); }
public async Task <Unit> Handle(CreateCategoryCommand request, CancellationToken cancellationToken) { var entity = new Domain.Models.Category { Name = request.Name, AddedDateTime = dateTime.Now }; context.Categories.Add(entity); await context.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public ICategory Update(Domain.Models.Category entity) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } var sEntity = context.Categories.Find(entity.Id); sEntity.Name = entity.Name; sEntity.LastModifiedOn = DateTime.Now; context.SaveChanges(); return(sEntity.ToDomainEntity()); }
public async Task <int> UpdateAsync(Domain.Models.Category category) { var equalityComparer = new SubcategoryEqualityComparer(); var subcategoriesInDatabase = await _unit.SubcategoryRepository.FindByCategory(category.Id); var subcategoriesToDelete = subcategoriesInDatabase.Except(category.Subcategories, equalityComparer); _unit.SubcategoryRepository.Delete(subcategoriesToDelete); var subcategoriesToAdd = category.Subcategories.Except(subcategoriesInDatabase, equalityComparer); foreach (var s in subcategoriesToAdd) { s.CategoryId = category.Id; _unit.SubcategoryRepository.Add(s); } _unit.CategoryRepository.Update(category.Id, category); return(await _unit.CommitChangesAsync()); }
public void Setup() { var context = new Domain.DataAccess.MahourContext(); _category = context.CategoryTable.FirstOrDefault(); if (_category == null) { var Category = new Domain.Models.Category() { ID = DateTime.Now.Ticks.ToString(), Name = "test" }; context.CategoryTable.Add(Category); _category = Category; } }
public async Task <Response> ActionAsync(Request request) { var category = new Domain.Models.Category { CategoryName = request.CategoryName, OGTags = request.OGTags, Description = request.Description, Image = _fileManager.SaveCategoryImage(request.Image) }; await _categoryManager.CreateCategory(category); return(new Response { Id = category.Id, CategoryName = category.CategoryName, OGTags = category.OGTags, Description = category.Description, CurrentImage = category.Image }); }
public void RemoveCategory() { _container = EntityContainer.RemoveableContainer.ContainerConfig <EntityService.Entities.Category.ModifiableCategory>(_category.ID); try { using (var scope = _container.BeginLifetimeScope()) { var removeableCategory = scope.Resolve <EntityService.Interfaces.IRemoveable>(); removeableCategory.Remove(); } } catch (Exception error) { Assert.Fail(error.Message); } finally { _category = new Domain.DataAccess.MahourContext().CategoryTable.FirstOrDefault(); } }
public async Task <long> Handle(CreateCategoryCommand request, CancellationToken cancellationToken) { var category = new Domain.Models.Category { UserId = request.UserId, Name = request.Name.Trim() }; var categoryList = await _context.Category .Where(x => x.UserId == request.UserId) .ToListAsync(); if (categoryList.Exists(x => x.Name.ToLower().Trim() == category.Name.ToLower().Trim())) { throw new ArgumentException("Already Exists", nameof(request.Name)); } _context.Category.Add(category); await _context.SaveChangesAsync(cancellationToken); return(category.Id); }
public void EditCategory() { _container = EntityContainer.EditableContainer <Domain.Models.Category> .ContainerConfig(_category.ID); try { using (var scope = _container.BeginLifetimeScope()) { var editableCategory = scope.Resolve <EntityService.Interfaces.IEditable <Domain.Models.Category> >(); var Category = new Domain.Models.Category() { Name = "edit test" }; editableCategory.Edit(Category); } } catch (Exception error) { Assert.Fail(error.Message); } }
public async Task <int> DeleteAsync(Domain.Models.Category category) { _unit.CategoryRepository.Delete(category); return(await _unit.CommitChangesAsync()); }
public SentPostViewModel( int id, string title, string content, string headerPhotoPath, DateTime sentDate, Domain.Models.Blog blog = null, Domain.Models.Category category = null, Domain.Models.Post approvedPost = null) { Id = id; Title = title; Content = content; HeaderPhotoPath = headerPhotoPath;; SentDate = sentDate.ToShortDateString(); IsApproved = approvedPost != null; if (blog != null) { Blog = new BlogViewModel(blog.Id, blog.Title); } if (category != null) { Category = new CategoryViewModel(category.Id, category.Title); } if (approvedPost != null) { ApprovedPost = new PostViewModel(approvedPost.Id, approvedPost.Title, approvedPost.Content, approvedPost.IsActive, approvedPost.HeaderPhotoFilePath, approvedPost.DatePublished, approvedPost.Blog, approvedPost.Category); } }
public async Task <IActionResult> Put([FromBody] Domain.Models.Category category) { await _categoryService.UpdateAsync(category); return(Ok()); }
public PostViewModel( int id, string title, string content, bool isActive, string headerPhotoPath, DateTime publishDate, Domain.Models.Blog blog = null, Domain.Models.Category category = null) { Id = id; Title = title; Content = content; HeaderPhotoPath = headerPhotoPath; IsActive = isActive; Url = ContentUrlGenerator.GenerateUrl(id, title); PublishDate = publishDate.ToShortDateString(); if (blog != null) { Blog = new BlogViewModel(blog.Id, blog.Title); } if (category != null) { Category = new CategoryViewModel(category.Id, category.Title); } }