public void Add(CategoryCreateModel category) { if (!_typesRepository.Add(new Category(category))) { throw new ApplicationException(); } }
public void CreateCategory(CategoryCreateModel model) { using (UnitOfWork unitOfWork = _unitOfWorkFactory.Create()) { unitOfWork.Categories.Create(Mapper.Map <Category>(model)); } }
public async Task <IActionResult> Create([FromBody] CategoryCreateModel category) { if (ModelState.IsValid) { CategoryResultModel response = await this.categoryService.CreateCategory(category.Name, category.Description); if (!response.Success) { FailedResponseModel badResponse = new FailedResponseModel() { Errors = response.Errors }; return(BadRequest(badResponse)); } CategorySuccessResponseModel successResponse = new CategorySuccessResponseModel() { Name = response.Name }; return(Ok(successResponse)); } return(BadRequest(new FailedResponseModel { Errors = ModelState.Values.SelectMany(x => x.Errors.Select(y => y.ErrorMessage)) })); }
public async Task Create_ValidModel_RedirectsToIndex() { // Arrange var testCategoryToCreate = new CategoryCreateModel { CategoryName = "Test category for create", Description = "Test category for create description" }; var testCategory = new Category { CategoryId = 27, CategoryName = "Test category for create", Description = "Test category for create description" }; var mapperMock = new Mock <IMapper>(); mapperMock.Setup(x => x.Map <CategoryCreateModel, Category>(testCategoryToCreate)) .Returns(testCategory); var categoriesServiceMock = new Mock <ICategoriesService>(); categoriesServiceMock.Setup(x => x.CreateCategoryAsync(testCategory)) .ReturnsAsync(testCategory); var controller = new CategoriesController(categoriesServiceMock.Object, mapperMock.Object); // Act var result = await controller.Create(testCategoryToCreate); // Assert var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result); Assert.Null(redirectToActionResult.ControllerName); Assert.Equal("Index", redirectToActionResult.ActionName); }
public static Category toEntity(this CategoryCreateModel categoryCreate) { return(new Category() { Categoryname = categoryCreate.categoryName, Id = categoryCreate.categoryID.Value }); }
public void CreateCategory(CategoryCreateModel model) { using (var unitOfWork = _unitOfWorkFactory.Create()) { var category = Mapper.Map <Category>(model); unitOfWork.Categories.Create(category); } }
public async Task <IActionResult> Create(CategoryCreateModel category) { var model = new Category { CategoryId = Guid.NewGuid().ToString(), name = category.name }; await _categoryRepo.add(model); return(Ok()); }
public async Task <IActionResult> Post([FromBody] CategoryCreateModel categoryCreateModel) { if (await _categoryService.Exists(categoryCreateModel.Title)) { return(Conflict("Such category already exists")); } CategoryDto categoryCreateDto = _mapper.Map <CategoryDto>(categoryCreateModel); CategoryDto createdCategoryDto = await _categoryService.CreateCategory(categoryCreateDto); return(CreatedAtAction(nameof(Get), new { id = createdCategoryDto.CategoryId }, createdCategoryDto)); }
public async Task <IActionResult> Create(CategoryCreateModel category) { if (ModelState.IsValid) { await _categoriesService.CreateCategoryAsync(_mapper.Map <CategoryCreateModel, Category>(category)); return(RedirectToAction(nameof(Index))); } return(View(_mapper.Map <CategoryViewModel>(category))); }
public ActionResult <CategoryReadModel> Create(CategoryCreateModel category) { var categoryModel = _mapper.Map <Category>(category); _categoryService.Create(categoryModel); _categoryService.SaveChanges(); var categoryReadModel = _mapper.Map <CategoryReadModel>(categoryModel); return(CreatedAtRoute(nameof(GetById), new { Id = categoryReadModel.Id }, categoryReadModel)); //return Ok(categoryReadModel); }
public async Task <IActionResult> UpdateCategory([FromBody] CategoryCreateModel createCategoryDtoIn) { //if (!ModelState.IsValid) //{ // return BadRequest(ModelState); //} var model = mapper.Map <CategoryModel>(createCategoryDtoIn); var category = await categoryService.UpdateCategory(model); return(Ok(category)); }
public async Task <IActionResult> Create(CategoryCreateModel model) { if (!ModelState.IsValid) { return(View(model)); } var id = Guid.NewGuid(); await _commands.Send(new CreateCategoryCommand { Id = id, Name = model.Name }); return(RedirectToAction("ForCategoryCreation", "Wait", new { Id = id })); }
public async Task <ActionResult> Edit(Guid id) { var category = await AuctionFacade.GetCategoryAsync(id); var model = new CategoryCreateModel { Category = category, ParentCategory = category.Parent == null ? "" : category.Parent.Name }; return(View(model)); }
public async Task <ActionResult> Create(CategoryCreateModel model) { try { await AuctionFacade.CreateCategoryWithinParentCategoryNameAsync(model.Category, model.ParentCategory); return(RedirectToAction("Index")); } catch { return(View()); } }
public IActionResult Create(CategoryCreateModel model) { try { _categoryService.CreateCategory(model); return(RedirectToAction("Index")); } catch (Exception ex) { return(StatusCode(500, ex.Message)); } }
public async Task <IActionResult> Create([FromBody] CategoryCreateModel subcategory) { if (string.IsNullOrWhiteSpace(subcategory.Name)) { return(BadRequest(ModelConstants.InvalidCategoryName)); } return(await this.Execute(true, false, async() => { string subcategoryId = await this.subcategories.Create(subcategory.Name); return this.Ok(new { subcategoryId = subcategoryId }); })); }
public async Task <IActionResult> Update(string id, [FromBody] CategoryCreateModel subcategory) { if (string.IsNullOrWhiteSpace(id) || string.IsNullOrWhiteSpace(subcategory.Name)) { return(BadRequest(ModelConstants.InvalidCategoryName)); } return(await this.Execute(true, false, async() => { await this.subcategories.Update(id, subcategory.Name); return this.Ok(); })); }
public async Task <ActionResult> Edit(Guid id, CategoryCreateModel model) { try { if (model.ParentCategory != null) { model.Category.ParentId = (await AuctionFacade.GetCategoryIdsByNameAsync(model.ParentCategory)).SingleOrDefault(); } await AuctionFacade.EditCategory(model.Category); return(RedirectToAction("Index")); } catch { return(View()); } }
public async Task <IActionResult> Update(string id, [FromBody] CategoryCreateModel category) { var s = ""; System.Console.WriteLine(s); if (string.IsNullOrWhiteSpace(id) || string.IsNullOrWhiteSpace(category.Name)) { return(BadRequest(ModelConstants.InvalidCategoryName)); } return(await this.Execute(true, false, async() => { await this.categories.UpdateName(id, category.Name); return this.Ok(); })); }
public IActionResult createCategory([FromBody] CategoryCreateModel categoryCreate) { if (!ModelState.IsValid) { return(BadRequest()); // bookRequest.Authors = _bookRepository.GetAll(); } if (_categoryRepository.GetAll().Where(x => x.Categoryname == categoryCreate.categoryName).Any()) { return(Content("The Book Title is in Database Already!")); } else { _categoryRepository.Create(categoryCreate.toEntity()); return(Ok(categoryCreate)); } }
public ActionResult Create(CategoryCreateModel createModel) { if (!ModelState.IsValid) { return(View(createModel)); } try { _categoryService.Add(createModel); } catch (Exception e) { return(new HttpStatusCodeResult(500, e.Message)); } return(RedirectToAction("Index")); }
public ActionResult CreateAction(CategoryCreateModel model) { if (!ModelState.IsValid) { TempData["danger"] = "Error"; return(RedirectToAction("Create", "Category")); } Category cat = new Category { Name = model.Name, Id = Guid.NewGuid() }; _db.Categories.Add(cat); _db.SaveChanges(); TempData["success"] = "Category created"; return(RedirectToAction("Index", "Category")); }
public async Task <IActionResult> AddCategory([FromBody] CategoryCreateModel createCategoryModel) { try { if (!ModelState.IsValid) { return(BadRequest()); } var category = Mapper.Map <CategoryCreateModel, Category>(createCategoryModel); category.Status = Status.Active; await _categoryService.AddCategory(category); return(Ok(ModelFactory.CreateModel(category))); } catch (Exception ex) { return(BadRequest()); } }
public bool Add(CategoryCreateModel entity) { Guid?parent = entity.ParentId; if (parent == Guid.Empty) { parent = null; } Category category = new Category { Type = entity.Type, Name = entity.Name, ParentId = parent, CreatedBy = entity.CreatedBy, CreatedAt = entity.CreatedAt, ModifiedAt = entity.ModifiedAt, ModifiedBy = entity.ModifiedBy, CountryId = entity.CountryId }; return(_repository.Add(category)); }
public IActionResult Create([FromBody] CategoryCreateModel entity) { if (ModelState.IsValid) { string currentUser = HttpContext?.User?.Identity?.Name; if (!String.IsNullOrEmpty(currentUser)) { try { AuditedEntityMapper <CategoryCreateModel> .FillCreateAuditedEntityFields(entity, currentUser, CountryId); bool statusResult = _categoryService.Add(entity); if (statusResult) { return(Ok().WithSuccess(LOCALIZATION_SUCCESS_DEFAULT)); } else { return(NotFound().WithError(LOCALIZATION_ERROR_NOT_FOUND)); } } catch (Exception ex) { _logger.LogError(ex, ex.Message); return(RedirectToAction(nameof(Index)).WithError(ex.Message)); } } else { _logger.LogError(LOCALIZATION_ERROR_USER_MUST_LOGIN); return(NotFound().WithError(LOCALIZATION_ERROR_USER_MUST_LOGIN)); } } return(View(entity)); }
public async Task <ActionResult> CreateAsync(CategoryCreateModel model) => View(await _dbContext.AddCategoryAsync(model));
public IActionResult CreateCategory(CategoryCreateModel model) { _categoryService.CreateCategory(model); return(RedirectToAction("Index")); }
public async Task <IActionResult> AddCategory(CategoryCreateModel model) { await _categoryService.AddCategoryAsync(model); return(RedirectToAction("IndexСategoriesAdmin", "Category")); }
public async Task <IActionResult> Create(CategoryCreateModel inputModel) { var createdId = await service.CreateAsync(inputModel); return(Ok(new { id = createdId })); }
public async Task <IActionResult> Update([FromRoute] long id, CategoryCreateModel updateModel) { await service.UpdateAsync(id, updateModel); return(Ok()); }