예제 #1
0
 public static Categories AsModel(this CreateCategoryDTO category)
 {
     return(new Categories
     {
         Name = category.Name
     });
 }
예제 #2
0
        public async Task <IActionResult> CreateCategory([FromForm] CreateCategoryDTO createCategoryDTO)
        {
            var category = _mapper.Map <Category>(createCategoryDTO);
            await _categoryService.CreateAsync(category);

            return(Ok(category));
        }
예제 #3
0
        public async Task <CategoryDTO> Add(CreateCategoryDTO categoryDTO)
        {
            if (categoryDTO == null)
            {
                return(null);
            }

            if (categoryDTO.ParentCategoryId != null && await Get(categoryDTO.ParentCategoryId.Value) == null)
            {
                return(null);
            }

            var entity = await unitOfWork.Repository <Category>().Add(CategoryConverter.Convert(categoryDTO));


            if (entity == null)
            {
                return(null);
            }
            if (entity.ParentCategoryId != null)
            {
                entity.ParentCategory = await unitOfWork.Repository <Category>().Get(entity.ParentCategoryId.Value);
            }
            return(CategoryConverter.Convert(entity));
        }
예제 #4
0
        public ActionResult <Category> CreateNewCategory(CreateCategoryDTO createCategoryDTO)
        {
            var newCategory = new Category();

            newCategory.Name = createCategoryDTO.Name;
            var categoryFromDB = _categoryService.AddCategory(newCategory);

            return(Ok(categoryFromDB));
        }
예제 #5
0
        public async Task <IActionResult> CreateCategory(CreateCategoryDTO dto)
        {
            var category = Data.Domain.Entities.Forum.Category.Create(dto.Name, dto.Description);
            await _categoryRepo.Add(category);

            await _categoryRepo.Save();

            return(RedirectToAction("Index", "AdminPanel"));
        }
예제 #6
0
        public async Task <IActionResult> CreateCategory(CreateCategoryDTO category)
        {
            try {
                await this.m_categoryService.CreateCategoryAsync(category);

                return(this.Ok());
            } catch (Exception exception) {
                return(this.BadRequest(exception.Message));
            }
        }
 public ActionResult Create([Bind(Include = "id,name,displayname")] CreateCategoryDTO category)
 {
     if (ModelState.IsValid)
     {
         _categoryRepository.NewCategory(category);
         //_categoryRepository.Save();
         return(RedirectToAction("Index"));
     }
     return(View(category));
 }
        public void NewCategory(CreateCategoryDTO categoryDTO)
        {
            Category category = new Category()
            {
                name        = categoryDTO.name,
                displayname = categoryDTO.displayname
            };

            _categoryRepository.Insert(category);
        }
예제 #9
0
        public async Task <MessageModel <Category> > Post([FromBody] CreateCategoryDTO category)
        {
            var model = _mapper.Map <Category>(category);
            var ca    = await _service.Add(model);

            return(new MessageModel <Category>()
            {
                msg = "成功",
                response = ca
            });
        }
예제 #10
0
 public IActionResult Create(CreateCategoryDTO createCategoryDTO)
 {
     try
     {
         _categoryService.Create(createCategoryDTO);
         return(StatusCode(201));
     }
     catch (BusinessException ex)
     {
         return(BadRequest(ex.Message));
     }
 }
예제 #11
0
        public async Task <CategoryDTO> CreateCategory(CreateCategoryDTO category)
        {
            if (category.Name.Length < 3)
            {
                throw new Exception("Category Name should be atleast 3 characters long.");
            }
            var cat = category.AsModel();
            await _context.Categories.AddAsync(cat);

            await _context.SaveChangesAsync();

            return(cat.AsDTO());
        }
예제 #12
0
        public async Task <IActionResult> Add(CreateCategoryDTO createDto)
        {
            var categoryDto = await service.Add(createDto);

            if (categoryDto != null)
            {
                return(Ok());
            }
            else
            {
                return(BadRequest($"{nameof(categoryDto)} is null"));
            }
        }
예제 #13
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);
            }
        }
예제 #14
0
        public static Category Convert(CreateCategoryDTO category)
        {
            if (category == null)
            {
                throw new ArgumentNullException(nameof(category));
            }

            return(new Category
            {
                Title = category.Title,
                ParentCategoryId = category.ParentCategoryId,
                IsDeleted = false
            });
        }
예제 #15
0
        public async Task <ActionResult <Response <Int64> > > Create(CreateCategoryDTO command)
        {
            var validator = new Validator();

            if (!validator.Validate(command).IsValid)
            {
                return(BadRequest(new Response <int>("Invalid request, error valitaion")));
            }
            var result = await _categoryMenager.Create(command);

            if (!result.Succeeded)
            {
                return(BadRequest(result));
            }
            return(result);
        }
예제 #16
0
        /// <summary>
        /// this method updates category in database
        /// throws an exception on failure
        /// </summary>
        /// <param name="model">category model</param>
        /// <param name="id">category id</param>
        public async Task <string> UpdateAsync(CreateCategoryDTO model, int id)
        {
            var category = await _categoryRepository.GetByIdAsync(id);

            if (category == null)
            {
                throw new AuctionException("Category not found", System.Net.HttpStatusCode.NotFound);
            }

            _mapper.Map(model, category);
            _categoryRepository.Update(category);

            await _categoryRepository.SaveAsync();

            return("category has been updated succedfully");
        }
예제 #17
0
        /// <summary>
        /// this method adds a new category to the database
        /// throws an exception on failure
        /// </summary>
        /// <param name="model">category model</param>
        public async Task <Category> AddAsync(CreateCategoryDTO model)
        {
            bool CategoryIsExist = _categoryRepository.FindAll().FirstOrDefault(x => x.Name == model.Name) != null;

            if (CategoryIsExist)
            {
                throw new AuctionException("Category's alredy exist", System.Net.HttpStatusCode.Conflict);
            }

            var category = _mapper.Map <Category>(model);

            await _categoryRepository.AddAsync(category);

            await _categoryRepository.SaveAsync();

            return(category);
        }
예제 #18
0
        public async Task CreateCategoryAsync(CreateCategoryDTO category)
        {
            var createdBy = this.m_context.User.Claims.FirstOrDefault(u => u.Type == "Login")?.Value;

            var cat = new Category {
                Name      = category.Name,
                RusName   = category.RusName,
                CreatedBy = createdBy ?? "Admin",
                Active    = true
            };

            await this.m_catRepository.CreateAsync(cat);

            if (cat.Id <= 0)
            {
                throw new Exception("Creating error.");
            }
        }
예제 #19
0
        public async Task <IActionResult> CreateCategory(CreateCategoryDTO category)
        {
            try
            {
                var cat = await _adminservice.CreateCategory(category);

                return(StatusCode(201, cat));
            }
            catch (Exception e)
            {
                if (e.Message.Length > 0)
                {
                    return(BadRequest(e.Message));
                }
                else
                {
                    throw;
                }
            }
        }
예제 #20
0
        public async Task <Response <Int64> > Create(CreateCategoryDTO createCategoryDTO)
        {
            // является ли новая категория вложенной.
            if (createCategoryDTO.ParentId != null)
            {
                // ищем в БД указанного родителя
                var isExist = await _categoryRepo.CategoryExist(e => e.Id == createCategoryDTO.ParentId);

                // если родитель не найден в БД, то возращаем ошибку
                if (!isExist)
                {
                    return(new Response <Int64>("Category Not Found."));
                }
            }

            Category category = _mapper.Map <Category>(createCategoryDTO);

            _categoryRepo.AddAsync(category);
            return(new Response <Int64>(category.Id));
        }
예제 #21
0
        public async Task <ActionResult> CreateCategory(CreateCategoryDTO categoryModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = await _adminService.CreateCategoryAsync(categoryModel);

            if (result)
            {
                return(Ok());
            }
            else
            {
                return(Problem(
                           title: "Create category error.",
                           detail: "Error occured on creating new category. Try again.",
                           statusCode: 500));
            }
        }
예제 #22
0
 public void Create(CreateCategoryDTO categoryDTO)
 {
     this.ValidateCategoryName(categoryDTO.Name);
     _categoryRepository.Create(new Category(categoryDTO.Name));
 }
예제 #23
0
 public async Task AddCategory(CreateCategoryDTO category)
 {
     Shop.Core.Domain.Category model = new Shop.Core.Domain.Category(category.Id, category.Name, category.Description);
     await categoryRepository.AddCategory(model);
 }
예제 #24
0
 public async Task <IActionResult> CreateCategory([FromBody] CreateCategoryDTO category)
 {
     return(Ok(await _categoryService.AddAsync(category)));
 }
예제 #25
0
 public async Task <IActionResult> UpdateCategory(int categoryId, [FromBody] CreateCategoryDTO category)
 {
     return(Ok(await _categoryService.UpdateAsync(category, categoryId)));
 }