예제 #1
0
        protected async override Task CustomSeedAsync()
        {
            var categories = new List <string>
            {
                "work",
                "sport",
                "hobby"
            };

            await Task.WhenAll(categories.Select(x => _categoryRepository.AddAsync(new Category(x))));
        }
예제 #2
0
        protected override Task CustomSeed()
        {
            var categories = new List <string>
            {
                "Work",
                "Sport",
                "Hobby"
            };

            return(Task.WhenAll(categories.Select(x => _repository.AddAsync(new Category(x)))));
        }
예제 #3
0
        public async Task <IActionResult> Create(Category category)
        {
            if (ModelState.IsValid)
            {
                category.CategoryId = Guid.NewGuid();
                await _context.AddAsync(category);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
예제 #4
0
        public async Task <ReadCategoryModel> AddCategoryAsync(CreateCategoryModel model, CancellationToken cancellationToken)
        {
            var category = _mapper.Map <Category>(model);

            category.IconId = await _fileService.AddOrUpdateFileByIdAsync(model.Icon, category.IconId, cancellationToken);

            await _categoryRepository.AddAsync(category, cancellationToken);

            await _unitOfWork.SaveChangesAsync(cancellationToken);

            return(_mapper.Map <ReadCategoryModel>(category));
        }
예제 #5
0
        public async Task <ActionResult> AddNewCategory(SaveCategoryResource saveCategoryResource)
        {
            var category = mapper.Map <Category>(saveCategoryResource);

            await categoryRepository.AddAsync(category);

            await unitOfWork.SaveAsync();

            var categoryResource = mapper.Map <KeyValuePairResource>(category);

            return(Ok(categoryResource));
        }
        public async Task <ActionResult <Category> > PostCategory(CategoryDTO category)
        {
            var item = _categoryRepository.AddAsync(BaseEntity.CreateFrom <Category>(category));

            if (item != null)
            {
                await _categoryRepository.SaveAsync();

                return(CreatedAtAction("GetCategory", new { id = item.Id }, item));
            }
            return(BadRequest());
        }
예제 #7
0
        public async Task <IResultModel> Add(CategoryAddModel model)
        {
            var entity = _mapper.Map <CategoryEntity>(model);
            //if (await _repository.Exists(entity))
            //{
            //return ResultModel.HasExists;
            //}

            var result = await _repository.AddAsync(entity);

            return(ResultModel.Result(result));
        }
예제 #8
0
        public async Task <CategoryViewModel> Handle(CreateCategoryCommand command, CancellationToken cancellationToken)
        {
            var category = GetCategory(command);

            await _categoryRepository.AddAsync(category);

            await _categoryRepository.UnitOfWork.SaveEntitiesAsync(_domainEventsService, _mediator, cancellationToken);

            var categoryViewModel = _mapper.Map <CategoryViewModel>(category);

            return(categoryViewModel);
        }
예제 #9
0
        public async Task <IActionResult> Post([FromBody] Category category)
        {
            if (category.UserId <= 0 || String.IsNullOrEmpty(category.CategoryName))
            {
                return(new StatusCodeResult(StatusCodes.Status400BadRequest));
            }
            category.UpdatedTime = DateTime.Now;
            category.CreatedTime = DateTime.Now;
            category             = await _categoryRepository.AddAsync(category);

            return(Json(category));
        }
예제 #10
0
        public async Task RegisterAsync(string name, string description)
        {
            var category = await _categoryRepository.GetAsync(name);

            if (category != null)
            {
                throw new Exception($"Category with name '{name}' already exists.");
            }

            category = new Category(name, description);
            await _categoryRepository.AddAsync(category);
        }
예제 #11
0
        public async Task <CategoryResponse> SaveAsync(Category category)
        {
            try{
                await _categoryRepository.AddAsync(category);

                await _unitOfWork.CompleteAsync();

                return(new CategoryResponse(category));
            }catch (Exception ex) {
                return(new CategoryResponse($"An error occured when saving the category: {ex.Message}"));
            }
        }
예제 #12
0
        public async Task <string> SaveAsync(Category category)
        {
            try {
                await _categoryRepository.AddAsync(category);

                await _unitOfWork.CompleteAsync();

                return(MessageConstants.Saved);;
            } catch (Exception ex) {
                // Do some logging stuff
                return($"{MessageConstants.SavedWarning}: {ex.Message}");;
            }
        }
예제 #13
0
        public async Task <CategoryDto> AddAsync(CategoryCreateDto dto)
        {
            if (string.IsNullOrEmpty(dto.Name))
            {
                throw new ArticleException(ArticleErrorCodes.CategoryNameCannotBeNull, "Category Name field is mandatory.", dto);
            }

            var entity = dto.Adapt <Domain.Category>();

            entity = await _categoryRepository.AddAsync(entity);

            return(entity.Adapt <CategoryDto>());
        }
예제 #14
0
        public async Task <BaseResponse> AddAsync(AddCategoryRequest request)
        {
            var loggedUser = await _authenticationService.GetLoggedUserAsync();

            var category = _mapper.Map <AddCategoryRequest, Category>(request);

            category.UserId = loggedUser.User.Id;
            await _categoryRepository.AddAsync(category);

            await _unitOfWork.SaveChangesAsync();

            return(new BaseResponse());
        }
        public async Task <IActionResult> AddCategory(CategoryAddDto categoryAddDto)
        {
            Category addCategory = _mapper.Map <Category>(categoryAddDto);

            if (await _categoryRepository.AddAsync(addCategory))
            {
                return(Ok(addCategory));
            }
            else
            {
                return(BadRequest("Category Can't Added"));
            }
        }
        public async Task AddAsync(Guid id, Guid userId, string category, string name, string description, DateTime createdAt)
        {
            var activityCategry = await _categoryRepository.GetAsync(category);

            if (activityCategry == null)
            {
                await _categoryRepository.AddAsync(new Category(category));

                // throw new ActioException("category_not_found",$"Category {category} not found");
            }

            await _activityRepository.AddAsync(new Activity(id, userId, activityCategry, name, description, createdAt));
        }
예제 #17
0
        public static async Task <Category> SetOrGetExistingAsync(this ICategoryRepository repository, string name)
        {
            var @category = await repository.GetAsync(name);

            if (@category == null)
            {
                var id = Guid.NewGuid();
                @category = new Category(id, name);
                await repository.AddAsync(@category);
            }

            return(@category);
        }
        protected override async Task CustomSeederAsync()
        {
            var categories = new List <string>
            {
                "Work",
                "Sport",
                "hobby"
            };

            var user = new User("*****@*****.**", "Okosodovictor");

            await Task.WhenAll(categories.Select(x => _repo.AddAsync(new Category(x))));
        }
예제 #19
0
        public async Task <Guid> CreateAsync(string name, Guid userId)
        {
            var category = await _categoryRepository.GetAsync(name, userId);

            if (category != null)
            {
                throw new Exception($"Category with name: {name} already exist. ");
            }
            category = new Category(name, userId);
            await _categoryRepository.AddAsync(category);

            return(category.Id);
        }
예제 #20
0
        public async Task <CategoryResponse> SaveAsync(Category category)
        {
            try
            {
                await _categoryRepository.AddAsync(category);

                return(new CategoryResponse(category));
            }
            catch (Exception ex)
            {
                // Do some logging stuff
                return(new CategoryResponse($"An error occurred when saving the category: {ex.Message}"));
            }
        }
예제 #21
0
        public async Task <bool> CreateCategoryAsync(CreateCategoryDTO categoryModel)
        {
            if (string.IsNullOrEmpty(await _categoryRepository.GetCategoryNameAsync(categoryModel.CategoryName)))
            {
                var category = _mapper.Map <Category>(categoryModel);
                await _categoryRepository.AddAsync(category);

                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #22
0
        protected override async Task CustomSeedAsync()
        {
            var categories = new List <string>
            {
                "work",
                "sport",
                "hobby"
            };

            _logger.LogInformation($"Seeding DB");

            await Task.WhenAll(categories.Select(x
                                                 => _categoryRepository.AddAsync(new Category(x))));
        }
예제 #23
0
        public async Task <IActionResult> Post(CategoryIndexViewModel model)
        {
            var category = new Category
            {
                Id   = model.Id,
                Name = model.Name,
                Slug = model.Slug
            };
            await _categoryRepository.AddAsync(category);

            TempData["SM"] = "Вы успешно создали.";

            return(RedirectToAction("Index", "Category"));
        }
예제 #24
0
        public async Task <CategoryResponse> SaveAsync(Category category)
        {
            try {
                await _categoryRepository.AddAsync(category);

                await _unitOfWork.CompleteAsync();

                return(new CategoryResponse(category));
            }
            catch (Exception ex) {
                // Do some logging stuff
                return(new CategoryResponse($"An error occurred when saving the category: {ex.Message}", HttpStatusCode.InternalServerError));
            }
        }
        public async Task <IActionResult> PostAsync([FromBody] SaveCategoryResource resource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }

            var category = _mapper.Map <SaveCategoryResource, Category>(resource);
            await _categoryRepo.AddAsync(category);


            //var categoryResource = _mapper.Map<Category, CategoryResource>(result.Category);
            return(Ok());
        }
예제 #26
0
 private void MockCategories()
 {
     _categoryRepository.AddAsync(new Category(Guid.NewGuid(), "Down Jackets", false));
     _categoryRepository.AddAsync(new Category(Guid.NewGuid(), "Hoodies", false));
     _categoryRepository.AddAsync(new Category(Guid.NewGuid(), "Suits", false));
     _categoryRepository.AddAsync(new Category(Guid.NewGuid(), "Jeans", false));
     _categoryRepository.AddAsync(new Category(Guid.NewGuid(), "Casual Pants", false));
     _categoryRepository.AddAsync(new Category(Guid.NewGuid(), "Sunglass", false));
 }
        /// <inheritdoc/>
        public Task <string> Add(string name)
        {
            if (IsCategoryInDB(p =>
                               string.Equals(p.Name, name, StringComparison.CurrentCultureIgnoreCase),
                               out var categories))
            {
                return(Task.FromResult <string>(null));
            }

            var newCategory = new Category {
                Name = name
            };

            return(_categoryRepository.AddAsync(_mapper.Map <CategoryDB>(newCategory)));
        }
예제 #28
0
        public void AddCategory(CategoryViewModel category)
        {
            try
            {
                var newCategory = new Category()
                {
                    ParrentCategoryId = category.ParrentCategoryId,
                    Name = category.Name
                };

                _categoryRepository.AddAsync(newCategory);
            }
            catch (Exception ex)
            { }
        }
예제 #29
0
        public async Task <CategoryResponse> SaveAsync(Category category)
        {
            try
            {
                await _categoryRepository.AddAsync(category);

                await _unitOfWork.CompleteAsync();

                return(new CategoryResponse(category));
            }
            catch (Exception e)
            {
                return(new CategoryResponse($"Ocurrió un Error: {e.Message}"));
            }
        }
예제 #30
0
        public async Task <IActionResult> Create([Bind("Title,Description,ParentId")] Category model)
        {
            if (ModelState.IsValid)
            {
                model.CreatedOnUtc = DateTime.UtcNow;

                await _categoryRepository.AddAsync(model);

                await _businessObject.UnitOfWork.CommitAsync();

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }