public async Task <ActionResult> Create(CategoriesInputViewModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest());
            }

            var data = await this.categoriesService.AddCategory(input);

            return(this.CreatedAtAction(
                       "AllCategories", new { Message = $"{data.Name} category created!", data }));
        }
        public async Task <ActionResult> Edit(CategoriesInputViewModel edit)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest());
            }

            var user = await this.userManager
                       .GetUserAsync(this.User); // TO DO LOOK ProductsService and add userId EditProduct(user.id, edit);

            var data = await this.categoriesService.EditProduct(edit);

            return(this.CreatedAtAction(
                       "AllCategories",
                       new { Message = $"{data.Name} category changed!", data }));
        }
Beispiel #3
0
        public async Task <Category> AddCategory(CategoriesInputViewModel category)
        {
            var currentCategory = await this.repositoryCategories.All()
                                  .FirstOrDefaultAsync(x => x.Name == category.Name);

            if (currentCategory == null)
            {
                currentCategory = new Category
                {
                    Name       = category.Name,
                    Created_On = DateTime.UtcNow,
                };

                await this.repositoryCategories.AddAsync(currentCategory);

                await this.repositoryCategories.SaveChangesAsync();
            }

            return(currentCategory);
        }
Beispiel #4
0
        public async Task <Category> EditProduct(CategoriesInputViewModel category)
        {
            var currentCategory = await this.repositoryCategories.All().FirstOrDefaultAsync(x => x.Id == category.Id);

            if (currentCategory != null)
            {
                this.repositoryCategories.Delete(currentCategory);

                currentCategory = new Category
                {
                    Id         = category.Id,
                    Name       = category.Name,
                    Created_On = DateTime.UtcNow,
                };

                await this.repositoryCategories.AddAsync(currentCategory);

                await this.repositoryCategories.SaveChangesAsync();
            }

            return(currentCategory);
        }