public void ShouldSaveProductCategory()
        {
            var supplierId = Guid.NewGuid();
            var model      = new ProductCategoryRequestModel()
            {
                SupplierId   = supplierId,
                CategoryName = "celular"
            };

            _supplierService.ExistsById(supplierId).Returns(true);

            _productService.Create(model);

            _productRepository.Received(1)
            .Create(Arg.Is <ProductCategory>(x => x.CategoryName.ToString() == "celular" && x.SupplierId == supplierId));
        }
Ejemplo n.º 2
0
        public HttpResponseMessage Create(HttpRequestMessage request, ProductCategoryViewModel productCategoryViewModel)
        {
            return(CreateHttpReponseMessage(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    response = request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    //Value Default
                    productCategoryViewModel.CreatedBy = "admin";
                    productCategoryViewModel.CreatedDate = DateTime.Now;

                    //Save
                    var newProductCategory = new ProductCategory();
                    newProductCategory.UpdateProductCategory(productCategoryViewModel);
                    _productCategoryService.Create(newProductCategory);
                    _productCategoryService.SaveChanges();

                    //Return
                    var responseData = Mapper.Map <ProductCategory, ProductCategoryViewModel>(newProductCategory);
                    response = request.CreateResponse(HttpStatusCode.Created, responseData);
                }
                return response;
            }));
        }
Ejemplo n.º 3
0
 public ActionResult SaveItem(ProductCategoryViewModel productCategoryVm)
 {
     if (ModelState.IsValid)
     {
         var errors = new Dictionary <string, string>();
         productCategoryVm.SeoAlias = TextHelper.ToUnsignString(productCategoryVm.Name);
         if (productCategoryVm.IsEdit == false)
         {
             _productCategoryService.Create(productCategoryVm);
         }
         else
         {
             _productCategoryService.Update(productCategoryVm);
         }
         _productCategoryService.Save();
         return(Json(new JsonResponse()
         {
             Success = true,
             Message = Constants.SaveDataSuccess
         }));
     }
     return(Json(new JsonResponse
     {
         Success = false,
         Message = Constants.SaveDataFailed,
         Errors = ModelState.Where(modelState => modelState.Value.Errors.Count > 0).ToDictionary(
             kvp => kvp.Key,
             kvp => kvp.Value.Errors.Select(e => e.ErrorMessage).FirstOrDefault()
             )
     }));
 }
Ejemplo n.º 4
0
        public HttpResponseMessage Create(HttpRequestMessage request, ProductCategoryViewModel productCategoryVM)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    request.CreateErrorResponse(HttpStatusCode.BadGateway, ModelState);
                }
                else
                {
                    ProductCategory objPC = new ProductCategory();
                    objPC.UpdateProductCategory(productCategoryVM);
                    objPC.CreateDate = DateTime.Now;
                    objPC.CreateBy = UserInfoInstance.UserCode;
                    objPC.Status = true;

                    bool check = productCategoryService.Create(objPC);
                    if (check)
                    {
                        productCategoryService.SaveChanges();
                        string msg = string.Format("Thêm mới thành công");
                        response = request.CreateResponse(HttpStatusCode.OK, msg);
                        return response;
                    }

                    string msgError = string.Format("Thêm mới thất bại! Thể loại {0} đã tồn tại.", productCategoryVM.ProductCategoryName);
                    response = request.CreateResponse(HttpStatusCode.BadGateway, msgError);
                }

                return response;
            }));
        }
        public HttpResponseMessage Create(HttpRequestMessage request, ProductCategoryViewModel productCategoryViewModel)
        {
            return(CreateHttpResponse(request, () => {
                HttpResponseMessage response;

                if (!ModelState.IsValid)
                {
                    response = request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var newProductCategory = new ProductCategory();

                    newProductCategory.UpdateProductCategory(productCategoryViewModel);
                    newProductCategory.CreatedDate = DateTime.Now;

                    _productCategoryService.Create(newProductCategory);

                    _productCategoryService.Save();

                    var responseData = Mapper.Map <ProductCategory, ProductCategoryViewModel>(newProductCategory);

                    response = request.CreateResponse(HttpStatusCode.Created, responseData);
                }

                return response;
            }));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Create(ProductCategory_Dto model)
        {
            model.Update_By   = User.FindFirst(ClaimTypes.Name).Value;
            model.Update_Time = DateTime.Now;
            var data = await _productCategoryService.Create(model);

            return(Ok(data));
        }
        public IHttpActionResult Post([FromBody] ProductCategory entity)
        {
            logger.Trace("Call ProductCategoriesController Post");

            var record = productCategoryService.Create(entity);

            return(Created(record));
        }
        public BaseResponse <BusinessException> Create(AddOrEditCategoryRequest <ProductCategoryViewModel> request)
        {
            BaseResponse <BusinessException> response = new BaseResponse <BusinessException>()
            {
                ResponseCode = BaseCode.SUCCESS,
                Message      = "Create product category success",
                MsgType      = BaseCode.SUCCESS_TYPE
            };

            try
            {
                if (string.IsNullOrEmpty(request.Model.Name))
                {
                    response.ResponseCode = BaseCode.VALIDATE_ERROR;
                    response.Message      = "The Name field is required";
                    response.MsgType      = BaseCode.ERROR_TYPE;
                    return(response);
                }

                if (request.Model.CategoryID <= 0)
                {
                    response.ResponseCode = BaseCode.VALIDATE_ERROR;
                    response.Message      = "The Category field is required";
                    response.MsgType      = BaseCode.ERROR_TYPE;
                    return(response);
                }

                if (productCategoryService.GetAll().Any(x => x.CategoryID == request.Model.CategoryID && x.Name.ToUpper().Equals(request.Model.Name.ToUpper())))
                {
                    response.ResponseCode = BaseCode.VALIDATE_ERROR;
                    response.Message      = "Update product category fail. This Name field is already in use";
                    response.MsgType      = BaseCode.ERROR_TYPE;
                    return(response);
                }

                ProductCategory objInsert = new ProductCategory()
                {
                    Name       = request.Model.Name,
                    Alias      = request.Model.Alias,
                    Sequence   = request.Model.Sequence,
                    IsHomeFlag = request.Model.IsHomeFlag,
                    IsActive   = request.Model.IsActive,
                    CategoryID = request.Model.CategoryID,
                    CreateBy   = request.UserID,
                    CreateDate = DateTime.Now,
                };
                productCategoryService.Create(objInsert);
                return(response);
            }
            catch (BusinessException ex)
            {
                response.ResponseCode = BaseCode.CRUD_ERROR;
                response.Message      = ex.Message;
                response.Data         = ex;
                response.MsgType      = BaseCode.ERROR_TYPE;
                return(response);
            }
        }
 public ActionResult Create(ProductCategoryViewModel vm, ProductCategory productCategory)
 {
     if (!ModelState.IsValid)
     {
         vm.Category = _categoryService.CategoryList();
         return(View(vm));
     }
     _productCategoryService.Create(productCategory);
     return(RedirectToAction("Index", "Home"));
 }
 public ActionResult <ProductCategory> Post([FromBody] ProductCategory value)
 {
     try
     {
         return(Ok(_productCategoryService.Create(value)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Ejemplo n.º 11
0
        public async Task <IActionResult> Create(ProductCategory_Dto model)
        {
            model.Update_By   = User.FindFirst(ClaimTypes.Name).Value;
            model.Update_Time = DateTime.Now;
            var result = await _productCategoryService.Create(model);

            if (result.Success)
            {
                await _hubContext.Clients.All.LoadDataProductCate();
            }
            return(Ok(result));
        }
        public IActionResult Create([FromBody] ProductCategoryDTO productCategoryDTO)
        {
            ProductCategory productCategory = new ProductCategory();

            productCategory.ProductCategoryName = productCategoryDTO.ProductCategoryName;
            //productCategory.CreatedBy = User.Identity.Name;
            productCategory.CreatedBy   = "Admin";
            productCategory.CreatedDate = DateTime.Now;
            var productCategoryEntity = _productCategoryService.Create(productCategory);
            var productCategories     = _mapper.Map <ProductCategoryDTO>(productCategoryEntity);

            return(Ok(productCategory));
        }
Ejemplo n.º 13
0
        public async Task <ActionResult <Data.Models.ProductCategory> > PostCategory(Data.Models.ProductCategory category)
        {
            if (category == null)
            {
                return(BadRequest());
            }

            category.Slug = Slug.Generate(category.Title);

            await _categoryService.Create(category);

            return(CreatedAtAction("GetCategory", new { id = category.Id }, category));
        }
Ejemplo n.º 14
0
        public ActionResult Create(ProductCategoryViewModels model)
        {
            var productCategory = new ProductCategory()
            {
                Id           = Guid.NewGuid(),
                Name         = model.Name,
                Image        = model.Image,
                CreateDate   = DateTime.Now,
                CreateBy     = User.Identity.GetUserName(),
                ModifiedDate = DateTime.Now,
                Status       = true,
            };
            var result = _productCategoryService.Create(productCategory);

            if (result == true)
            {
                return(RedirectToAction("Index"));
            }
            return(View());
        }
Ejemplo n.º 15
0
        public HttpResponseMessage Create(HttpRequestMessage request, ProductCategoryViewModel productCategoryViewModel)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    response = request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    ProductCategory productCategory = new ProductCategory();
                    productCategory.UpdateProductCategory(productCategoryViewModel);
                    var model = _productCategoryService.Create(productCategory);
                    var mapper = Mapper.Map <ProductCategory, ProductCategoryViewModel>(model);
                    _productCategoryService.SaveChange();

                    response = request.CreateResponse(HttpStatusCode.Created, mapper);
                }
                return response;
            }));
        }
        public async Task <IActionResult> Create([FromBody] ProductCategoryRequestModel request)
        {
            await _productCategoryService.Create(request);

            return(Accepted());
        }
        public ActionResult Post(ProductCategory vm)
        {
            ProductCategory pt       = vm;
            var             settings = new ProductTypeSettingsService(_unitOfWork).GetProductTypeSettingsForDocument(vm.ProductTypeId);

            if (ModelState.IsValid)
            {
                if (vm.ProductCategoryId <= 0)
                {
                    pt.CreatedDate  = DateTime.Now;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy    = User.Identity.Name;
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.ObjectState  = Model.ObjectState.Added;
                    _ProductCategoryService.Create(pt);

                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        ViewBag.id   = vm.ProductTypeId;
                        ViewBag.Name = new ProductTypeService(_unitOfWork).Find(vm.ProductTypeId).ProductTypeName;
                        ViewBag.ProductCategoryCaption       = settings.ProductCategoryCaption ?? "Product Category";
                        ViewBag.SalesTaxProductCodeCaption   = "Default " + (settings.SalesTaxProductCodeCaption ?? "Sales Tax Product Code");
                        ViewBag.IsVisibleSalesTaxProductCode = settings.isVisibleSalesTaxProductCode ?? false;
                        return(View("Create", vm));
                    }

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId    = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.ProductCategry).DocumentTypeId,
                        DocId        = pt.ProductCategoryId,
                        ActivityType = (int)ActivityTypeContants.Added,
                    }));

                    return(RedirectToAction("Create", new { id = pt.ProductTypeId }).Success("Data saved successfully"));
                }
                else
                {
                    List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();
                    ProductCategory         temp    = _ProductCategoryService.Find(pt.ProductCategoryId);

                    ProductCategory ExRec = Mapper.Map <ProductCategory>(temp);

                    temp.ProductCategoryName          = pt.ProductCategoryName;
                    temp.ProductTypeId                = pt.ProductTypeId;
                    temp.DefaultSalesTaxProductCodeId = pt.DefaultSalesTaxProductCodeId;
                    temp.IsActive     = pt.IsActive;
                    temp.ModifiedDate = DateTime.Now;
                    temp.ModifiedBy   = User.Identity.Name;
                    temp.ObjectState  = Model.ObjectState.Modified;
                    _ProductCategoryService.Update(temp);


                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = ExRec,
                        Obj   = temp,
                    });
                    XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);
                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        ViewBag.id   = vm.ProductTypeId;
                        ViewBag.Name = new ProductTypeService(_unitOfWork).Find(vm.ProductTypeId).ProductTypeName;
                        ViewBag.ProductCategoryCaption       = settings.ProductCategoryCaption ?? "Product Category";
                        ViewBag.SalesTaxProductCodeCaption   = "Default " + (settings.SalesTaxProductCodeCaption ?? "Sales Tax Product Code");
                        ViewBag.IsVisibleSalesTaxProductCode = settings.isVisibleSalesTaxProductCode ?? false;
                        return(View("Create", pt));
                    }


                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId       = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.ProductCategry).DocumentTypeId,
                        DocId           = temp.ProductCategoryId,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        xEModifications = Modifications,
                    }));

                    return(RedirectToAction("Index", new { id = pt.ProductTypeId }).Success("Data saved successfully"));
                }
            }

            ViewBag.id   = vm.ProductTypeId;
            ViewBag.Name = new ProductTypeService(_unitOfWork).Find(vm.ProductTypeId).ProductTypeName;
            return(View("Create", vm));
        }