예제 #1
0
        public void CreateCategory(SaveCategoryDto saveCategoryDto)
        {
            var Category = _mapper.Map <SaveCategoryDto, Category>(saveCategoryDto);

            _unitOfWork.Category.Add(Category);
            _unitOfWork.Complete();
        }
예제 #2
0
        public void Add(SaveCategoryDto saveCategoryDto)
        {
            var cate = _mapper.Map <SaveCategoryDto, Category>(saveCategoryDto);

            _unitOfWork.Categories.Add(cate);
            _unitOfWork.Complete();
        }
예제 #3
0
        public void UpdateCategory(SaveCategoryDto saveCategoryDto)
        {
            var Category = _unitOfWork.Category.GetPro(saveCategoryDto.CategoryId);

            if (Category == null)
            {
                return;
            }
            _mapper.Map <SaveCategoryDto, Category>(saveCategoryDto, Category);
            _unitOfWork.Complete();
        }
예제 #4
0
        public async Task <IActionResult> SaveCategory([FromBody] SaveCategoryDto saveCategory)
        {
            var categoryDtoResult = await QueryProcessor.GetQueryHandler <SaveCategoryCommand, CategoryDto>(new SaveCategoryCommand(saveCategory, 1));

            if (categoryDtoResult.Failure)
            {
                return(BadRequest(categoryDtoResult.ErrorMessages));
            }

            return(Ok(categoryDtoResult.Object));
        }
예제 #5
0
        public void Update(SaveCategoryDto saveCategoryDto)
        {
            var cate = _unitOfWork.Categories.GetBy(saveCategoryDto.ID);

            if (cate == null)
            {
                return;
            }

            _mapper.Map <SaveCategoryDto, Category>(saveCategoryDto, cate);

            _unitOfWork.Complete();
        }
예제 #6
0
        public IActionResult OnGet(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var category = _context.GetCategory(id ?? default(int));

            if (category == null)
            {
                return(NotFound());
            }
            Category = _mapper.Map <CategoryDto, SaveCategoryDto>(category);

            return(Page());
        }
예제 #7
0
        public async Task <IActionResult> PutAsync(int id, [FromBody] SaveCategoryDto resource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }

            var category = _mapper.Map <SaveCategoryDto, Category>(resource);
            var result   = await _categoryService.UpdateAsync(id, category);

            if (!result.Success)
            {
                return(BadRequest(result.Message));
            }

            var CategoryDto = _mapper.Map <Category, CategoryDto>(result.Category);

            return(Ok(CategoryDto));
        }
        public async Task <IActionResult> AddCategoryAsync(SaveCategoryDto addCategoryDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var category = _mapper.Map <SaveCategoryDto, Category>(addCategoryDto);
            var response = await _categoryService.AddCategoryAsync(category);

            if (!response.Success)
            {
                return(BadRequest(new { response.Error }));
            }

            var resource = _mapper.Map <Category, CategoryDto>(response.Resource);

            return(Ok(resource));
        }
예제 #9
0
        public IActionResult Edit(CategoryEditVm model)
        {
            if (HttpContext.Session.GetInt32("LoginLevel") != 2)
            {
                ViewBag.checkLogin = 0;
                return(View("../Home/AddCart"));
            }
            if (ModelState.IsValid)
            {
                var categories = _service.GetAll();
                foreach (CategoryDto item in categories)
                {
                    if (item.Name.ToLower().Equals(model.Name.ToLower()) && item.ID != model.Id)
                    {
                        ViewBag.CategoryNameEditDuplicateErrorMessage = "Error";
                        var x = _categoryService.GetList();
                        ViewBag.StatusList = x.StatusList;
                        return(View(model));
                    }
                }

                CategoryDto     categoryDto     = _service.GetCate(model.Id);
                SaveCategoryDto saveCategoryDto = _mapper.Map <CategoryDto, SaveCategoryDto>(categoryDto);
                saveCategoryDto.Name        = model.Name;
                saveCategoryDto.Description = model.Description;
                saveCategoryDto.Status      = model.Status;
                saveCategoryDto.PhotoPath   = model.ExistPhotoPath;

                if (model.Photo != null)
                {
                    if (model.ExistPhotoPath != null)
                    {
                        string filePath = Path.Combine(_hostingEnvironment.WebRootPath, "images", model.ExistPhotoPath);
                        System.IO.File.Delete(filePath);
                    }
                    saveCategoryDto.PhotoPath = ProcessUploadedFile(model);
                }
                _service.Update(saveCategoryDto);
                return(View("Detail", _service.GetCate(saveCategoryDto.ID)));
            }
            return(View());
        }
예제 #10
0
        public async Task <IActionResult> UpdateCategoryAsync(int categoryId, SaveCategoryDto categoryDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var catDto = _mapper.Map <SaveCategoryDto, Category>(categoryDto);

            var response = await _categoryService.UpdateCategoryAsync(categoryId, catDto);

            if (!response.Success)
            {
                return(BadRequest(response.Error));
            }

            var category = _mapper.Map <Category, CategoryDto>(response.Resource);

            return(Ok(category));
        }
예제 #11
0
        public IActionResult Create(CategoryCreateVm model)
        {
            if (HttpContext.Session.GetInt32("LoginLevel") != 2)
            {
                ViewBag.checkLogin = 0;
                return(View("../Home/AddCart"));
            }
            if (!ModelState.IsValid)
            {
                var x = _categoryService.GetList();
                ViewBag.StatusList = x.StatusList;
                return(View());
            }

            string uniqueFileName = ProcessUploadedFile(model);

            SaveCategoryDto saveCategoryDto = new SaveCategoryDto()
            {
                Name        = model.Name,
                Description = model.Description,
                Status      = model.Status,
                PhotoPath   = uniqueFileName
            };

            var categories = _service.GetAll();

            foreach (CategoryDto item in categories)
            {
                if (saveCategoryDto.Name.ToLower() == item.Name.ToLower())
                {
                    var x = _categoryService.GetList();
                    ViewBag.StatusList = x.StatusList;
                    ViewBag.CategoryDuplicateErrorMessage = "Error";
                    return(View());
                }
            }

            _service.Add(saveCategoryDto);
            return(RedirectToAction("Index"));
        }
예제 #12
0
 public SaveCategoryCommand(SaveCategoryDto saveCategory, int languageId)
 {
     SaveCategory = saveCategory;
     LanguageId   = languageId;
 }