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
     });
 }
Beispiel #3
0
        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
            }));
        }
Beispiel #4
0
        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);
        }
Beispiel #6
0
        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());
        }
Beispiel #7
0
        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());
        }
Beispiel #8
0
        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;
            }
        }
Beispiel #9
0
        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
            });
        }
Beispiel #10
0
        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();
            }
        }
Beispiel #11
0
            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);
            }
Beispiel #12
0
        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);
            }
        }
Beispiel #13
0
 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);
            }
        }
Beispiel #15
0
        public async Task <IActionResult> Put([FromBody] Domain.Models.Category category)
        {
            await _categoryService.UpdateAsync(category);

            return(Ok());
        }
Beispiel #16
0
        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);
            }
        }