public ActionResult Create(CreateCategoryModel category) { if (!checkSession()) { return(RedirectToAction("login", "users")); } CategoryDAO categoryDAO = new CategoryDAO(); if (categoryDAO.CreateCategory(category)) { return(Json(new { MESSAGE = "1" })); } else { return(Json(new { MESSAGE = "0" })); } }
public IHttpActionResult insert([FromBody] CreateCategoryModel category) { Response response = new Response(); if (category.typeId < 0 || category.typeId > 3) { response.code = "202"; response.status = ("Vui lòng chọn loại sản phẩm"); return(Content <Response>(HttpStatusCode.Conflict, response)); } else if (Service.categoryDAO.checkExist(category.id) != null) { response = new Response("409", "Loại sản phẩm này đã tồn tại", null); return(Content <Response>(HttpStatusCode.Conflict, response)); } else { Service.categoryDAO.insertCategory(category.toCategory()); response = new Response("201", "Loại sản phẩm đã được thêm", category); return(Content <Response>(HttpStatusCode.Created, response)); } }
private void OnCreate() { // Open Create Page #region TEST var newCategory = new CreateCategoryModel { Name = "Name-" + this.Collection.Count, Coefficient = 0 }; var id = this.CategoryService.Create(newCategory); this.Collection.Insert(0, new CategoryModel { Id = id, Name = newCategory.Name, Coefficient = newCategory.Coefficient }); #endregion }
public static ProductCategory ToEntity(this CreateCategoryModel model, ProductCategory destination) { return(Mapper.Map(model, destination)); }
public static ProductCategory ToEntity(this CreateCategoryModel model) { return(Mapper.Map <CreateCategoryModel, ProductCategory>(model)); }
public IActionResult AddCategory() { var model = new CreateCategoryModel(); return(View(model)); }
public int Create(CreateCategoryModel model) { var newCategory = Mapper.Map <Category>(model); return(this.Unit.Categories.SaveItem(newCategory)); }
/// <summary> /// Insert new Category /// </summary> /// <param name="newCategoryModel">Category Model of Insertion</param> public void Create(CreateCategoryModel newCategoryModel) { //Insert Category _categoryService.Insert(newCategoryModel.Name); }
public async Task AddCategoryAsync_PagingInfo_ReturnsReturnPagingInfo_ReadCategoryModel(CreateCategoryModel model) { //Arrange var expectedValue = CategoryDumbData.GetReadCategoryModel(model); var cancellationToken = new CancellationToken(); _fileService.Setup(x => x.AddOrUpdateFileByIdAsync(It.IsAny <IFormFile>(), It.IsAny <Guid?>(), cancellationToken)).Returns(Task.FromResult((Guid?)expectedValue.IconId)); _categoryRepository.Setup(x => x.AddAsync(It.IsAny <Category>(), cancellationToken)).Returns(Task.FromResult(expectedValue)); _unitOfWork.Setup(x => x.SaveChangesAsync(cancellationToken)).Returns(Task.CompletedTask); // Act var response = await _categoryService.AddCategoryAsync(model, cancellationToken); expectedValue.Id = response.Id; // Assert _fileService.Verify(x => x.AddOrUpdateFileByIdAsync(It.IsAny <IFormFile>(), It.IsAny <Guid?>(), cancellationToken), Times.Once); _categoryRepository.Verify(x => x.AddAsync(It.IsAny <Category>(), cancellationToken), Times.Once); _unitOfWork.Verify(x => x.SaveChangesAsync(cancellationToken), Times.Once); response.Should().BeEquivalentTo(expectedValue); }
public async Task <ActionResult> Create([FromBody] CreateCategoryModel request) { return(await ICategoryService.Create(request)); }