コード例 #1
0
        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"
                }));
            }
        }
コード例 #2
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));
            }
        }
コード例 #3
0
        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
        }
コード例 #4
0
 public static ProductCategory ToEntity(this CreateCategoryModel model, ProductCategory destination)
 {
     return(Mapper.Map(model, destination));
 }
コード例 #5
0
 public static ProductCategory ToEntity(this CreateCategoryModel model)
 {
     return(Mapper.Map <CreateCategoryModel, ProductCategory>(model));
 }
コード例 #6
0
        public IActionResult AddCategory()
        {
            var model = new CreateCategoryModel();

            return(View(model));
        }
コード例 #7
0
ファイル: CategoryService.cs プロジェクト: VadyaVL/BudGetApp
        public int Create(CreateCategoryModel model)
        {
            var newCategory = Mapper.Map <Category>(model);

            return(this.Unit.Categories.SaveItem(newCategory));
        }
コード例 #8
0
 /// <summary>
 /// Insert new Category
 /// </summary>
 /// <param name="newCategoryModel">Category Model of Insertion</param>
 public void Create(CreateCategoryModel newCategoryModel)
 {
     //Insert Category
     _categoryService.Insert(newCategoryModel.Name);
 }
コード例 #9
0
        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);
        }
コード例 #10
0
 public async Task <ActionResult> Create([FromBody] CreateCategoryModel request)
 {
     return(await ICategoryService.Create(request));
 }