public static Categories AsModel(this CreateCategoryDTO category) { return(new Categories { Name = category.Name }); }
public async Task <IActionResult> CreateCategory([FromForm] CreateCategoryDTO createCategoryDTO) { var category = _mapper.Map <Category>(createCategoryDTO); await _categoryService.CreateAsync(category); return(Ok(category)); }
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)); }
public ActionResult <Category> CreateNewCategory(CreateCategoryDTO createCategoryDTO) { var newCategory = new Category(); newCategory.Name = createCategoryDTO.Name; var categoryFromDB = _categoryService.AddCategory(newCategory); return(Ok(categoryFromDB)); }
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")); }
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); }
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 }); }
public IActionResult Create(CreateCategoryDTO createCategoryDTO) { try { _categoryService.Create(createCategoryDTO); return(StatusCode(201)); } catch (BusinessException ex) { return(BadRequest(ex.Message)); } }
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()); }
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")); } }
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); } }
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 }); }
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); }
/// <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"); }
/// <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); }
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."); } }
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; } } }
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)); }
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)); } }
public void Create(CreateCategoryDTO categoryDTO) { this.ValidateCategoryName(categoryDTO.Name); _categoryRepository.Create(new Category(categoryDTO.Name)); }
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); }
public async Task <IActionResult> CreateCategory([FromBody] CreateCategoryDTO category) { return(Ok(await _categoryService.AddAsync(category))); }
public async Task <IActionResult> UpdateCategory(int categoryId, [FromBody] CreateCategoryDTO category) { return(Ok(await _categoryService.UpdateAsync(category, categoryId))); }