示例#1
0
        public async Task <IActionResult> SearchName(string employeeName)
        {
            if (string.IsNullOrEmpty(employeeName))
            {
                return(BadRequest());
            }

            var result = await _service.SearchNameAsync(e => e.EmployeeName.Contains(employeeName));

            if (result.ResultStatus == ResultStatus.Error)
            {
                return(BadRequest(new ErrorDto
                {
                    Message = ApiResultMessages.ResultMessage(false),
                    ResultStatus = result.ResultStatus
                }));
            }

            return(Ok(new EmployeeListDto
            {
                Employees = result.Data,
                ResultStatus = result.ResultStatus,
                Message = ApiResultMessages.ResultMessage(true)
            }));
        }
        public async Task <IActionResult> SearchName(string memberCustomerName)
        {
            if (string.IsNullOrEmpty(memberCustomerName))
            {
                return(BadRequest());
            }

            var result = await _service.SearchNameAsync(m => m.MemberCustomerName.Contains(memberCustomerName));

            if (result.ResultStatus == ResultStatus.Error)
            {
                return(BadRequest(new ErrorDto
                {
                    Message = ApiResultMessages.ResultMessage(false),
                    ResultStatus = result.ResultStatus
                }));
            }

            return(Ok(new MemberCustomerListDto
            {
                MemberCustomers = result.Data,
                ResultStatus = result.ResultStatus,
                Message = ApiResultMessages.ResultMessage(true)
            }));
        }
        public async Task <IActionResult> GetSupplierWithProductsByIdAsync(int id)
        {
            if (id < 1)
            {
                return(BadRequest());
            }

            var result = await _supplierService.GetSupplierWithProductsByIdAsync(id);

            if (result.ResultStatus == ResultStatus.Error)
            {
                return(BadRequest(new ErrorDto
                {
                    Message = ApiResultMessages.ResultMessage(false),
                    ResultStatus = result.ResultStatus
                }));
            }

            return(Ok(new SupplierWithProductsDto
            {
                Products = _mapper.Map <SupplierWithProductsDto>(result.Data).Products,
                ResultStatus = result.ResultStatus,
                Message = ApiResultMessages.ResultMessage(true)
            }));
        }
        public IActionResult Update([FromBody] ProductUpdateDto productUpdateDto)
        {
            var oldProduct = _productService.GetByIdAsync(productUpdateDto.Id).Result;

            var productUpdate = _mapper.Map <ProductUpdateDto, Product>(productUpdateDto, oldProduct.Data);


            var result = _productService.Update(productUpdate);

            if (result.ResultStatus == ResultStatus.Error)
            {
                return(BadRequest(new ErrorDto
                {
                    Message = ApiResultMessages.ResultMessage(false),
                    ResultStatus = result.ResultStatus
                }));
            }

            return(Ok(new ProductDto
            {
                Product = result.Data,
                Message = ApiResultMessages.ResultMessage(true),
                ResultStatus = result.ResultStatus
            }));
        }
示例#5
0
        public IActionResult Update([FromBody] CategoryUpdateDto categoryUpdateDto)
        {
            var oldCategory = _categoryService.GetByIdAsync(categoryUpdateDto.Id).Result;

            var categoryUpdate = _mapper.Map <CategoryUpdateDto, Category>(categoryUpdateDto, oldCategory.Data);


            var result = _categoryService.Update(categoryUpdate);

            if (result.ResultStatus == ResultStatus.Error)
            {
                return(BadRequest(new ErrorDto
                {
                    Message = ApiResultMessages.ResultMessage(false),
                    ResultStatus = result.ResultStatus
                }));
            }

            return(Ok(new CategoryDto
            {
                Category = result.Data,
                Message = ApiResultMessages.ResultMessage(true),
                ResultStatus = result.ResultStatus
            }));
        }
        public IActionResult Update([FromBody] SupplierUpdateDto supplierUpdateDto)
        {
            var oldSupplier = _supplierService.GetByIdAsync(supplierUpdateDto.Id).Result;

            var supplierUpdate = _mapper.Map <SupplierUpdateDto, Supplier>(supplierUpdateDto, oldSupplier.Data);


            var result = _supplierService.Update(supplierUpdate);

            if (result.ResultStatus == ResultStatus.Error)
            {
                return(BadRequest(new ErrorDto
                {
                    Message = ApiResultMessages.ResultMessage(false),
                    ResultStatus = result.ResultStatus
                }));
            }

            return(Ok(new SupplierDto
            {
                Supplier = result.Data,
                Message = ApiResultMessages.ResultMessage(true),
                ResultStatus = result.ResultStatus
            }));
        }
示例#7
0
        public async Task <IActionResult> SearchName(string categoryName)
        {
            if (string.IsNullOrEmpty(categoryName))
            {
                return(BadRequest());
            }

            var result = await _categoryService.SearchNameAsync(c => c.CategoryName.Contains(categoryName));

            if (result.ResultStatus == ResultStatus.Error)
            {
                return(BadRequest(new ErrorDto
                {
                    Message = ApiResultMessages.ResultMessage(false),
                    ResultStatus = result.ResultStatus
                }));
            }

            return(Ok(new CategoryListDto
            {
                Categories = result.Data,
                ResultStatus = result.ResultStatus,
                Message = ApiResultMessages.ResultMessage(true)
            }));
        }
        public async Task <IActionResult> SearchName(string productName)
        {
            if (string.IsNullOrEmpty(productName))
            {
                return(BadRequest());
            }

            var result = await _productService.SearchNameAsync(p => p.ProductName.Contains(productName));

            if (result.ResultStatus == ResultStatus.Error)
            {
                return(BadRequest(new ErrorDto
                {
                    Message = ApiResultMessages.ResultMessage(false),
                    ResultStatus = result.ResultStatus
                }));
            }

            return(Ok(new ProductListDto
            {
                Products = result.Data,
                ResultStatus = result.ResultStatus,
                Message = ApiResultMessages.ResultMessage(true)
            }));
        }
        public async Task <IActionResult> GetProductWithSupplierByIdAsync(int id)
        {
            if (id < 1)
            {
                return(BadRequest());
            }

            var result = await _productService.GetProductWithSupplierByIdAsync(id);

            if (result.ResultStatus == ResultStatus.Error)
            {
                return(BadRequest(new ErrorDto
                {
                    Message = ApiResultMessages.ResultMessage(false),
                    ResultStatus = result.ResultStatus
                }));
            }

            return(Ok(new ProductWithSupplierDto
            {
                Supplier = _mapper.Map <ProductWithSupplierDto>(result.Data).Supplier,
                ResultStatus = result.ResultStatus,
                Message = ApiResultMessages.ResultMessage(true)
            }));
        }
示例#10
0
        public async Task <IActionResult> Create([FromBody] CategoryAddDto categoryAddDto)
        {
            var category = _mapper.Map <Category>(categoryAddDto);

            var result = await _categoryService.AddAsync(category);

            if (result.ResultStatus == ResultStatus.Error)
            {
                return(BadRequest(new ErrorDto
                {
                    Message = ApiResultMessages.ResultMessage(false),
                    ResultStatus = result.ResultStatus
                }));
            }

            return(Created(string.Empty, categoryAddDto));
        }
示例#11
0
        public IActionResult RemoveAll([FromBody] IEnumerable <CategoryListDelete> categories)
        {
            var categoryList = _mapper.Map <IEnumerable <Category> >(categories);

            var result = _categoryService.DeleteRange(categoryList);

            if (result.ResultStatus == ResultStatus.Error)
            {
                return(BadRequest(new ErrorDto
                {
                    Message = ApiResultMessages.ResultMessage(false),
                    ResultStatus = result.ResultStatus
                }));
            }

            return(Ok(ApiResultMessages.ResultMessage(true)));
        }
        public async Task <IActionResult> CreateAll([FromBody] IEnumerable <ProductAddDto> productsAddDtos)
        {
            var products = _mapper.Map <IEnumerable <Product> >(productsAddDtos);

            var result = await _productService.AddRangeAsync(products);

            if (result.ResultStatus == ResultStatus.Error)
            {
                return(BadRequest(new ErrorDto
                {
                    Message = ApiResultMessages.ResultMessage(false),
                    ResultStatus = result.ResultStatus
                }));
            }

            return(Created(string.Empty, productsAddDtos));
        }
        public async Task <IActionResult> Create([FromBody] ProductAddDto productAddDto)
        {
            var product = _mapper.Map <Product>(productAddDto);

            var result = await _productService.AddAsync(product);

            if (result.ResultStatus == ResultStatus.Error)
            {
                return(BadRequest(new ErrorDto
                {
                    Message = ApiResultMessages.ResultMessage(false),
                    ResultStatus = result.ResultStatus
                }));
            }

            return(Created(string.Empty, productAddDto));
        }
        public async Task <IActionResult> CreateAll([FromBody] IEnumerable <MemberCustomersAddDto> memberCustomersAddDto)
        {
            var memberCustomers = _mapper.Map <IEnumerable <MemberCustomer> >(memberCustomersAddDto);

            var result = await _service.AddRangeAsync(memberCustomers);

            if (result.ResultStatus == ResultStatus.Error)
            {
                return(BadRequest(new ErrorDto
                {
                    Message = ApiResultMessages.ResultMessage(false),
                    ResultStatus = result.ResultStatus
                }));
            }

            return(Created(string.Empty, memberCustomersAddDto));
        }
        public async Task <IActionResult> Create([FromBody] SupplierAddDto supplierAddDto)
        {
            var supplier = _mapper.Map <Supplier>(supplierAddDto);

            var result = await _supplierService.AddAsync(supplier);

            if (result.ResultStatus == ResultStatus.Error)
            {
                return(BadRequest(new ErrorDto
                {
                    Message = ApiResultMessages.ResultMessage(false),
                    ResultStatus = result.ResultStatus
                }));
            }

            return(Created(string.Empty, supplierAddDto));
        }
        public IActionResult RemoveAll([FromBody] IEnumerable <ProductListDelete> products)
        {
            var productList = _mapper.Map <IEnumerable <Product> >(products);

            var result = _productService.DeleteRange(productList);

            if (result.ResultStatus == ResultStatus.Error)
            {
                return(BadRequest(new ErrorDto
                {
                    Message = ApiResultMessages.ResultMessage(false),
                    ResultStatus = result.ResultStatus
                }));
            }

            return(Ok(ApiResultMessages.ResultMessage(true)));
        }
示例#17
0
        public async Task <IActionResult> Create([FromBody] EmployeesAddDto employeesAddDto)
        {
            var employee = _mapper.Map <Employee>(employeesAddDto);

            var result = await _service.AddAsync(employee);

            if (result.ResultStatus == ResultStatus.Error)
            {
                return(BadRequest(new ErrorDto
                {
                    Message = ApiResultMessages.ResultMessage(false),
                    ResultStatus = result.ResultStatus
                }));
            }

            return(Created(string.Empty, employeesAddDto));
        }
示例#18
0
        public async Task <IActionResult> CreateAll([FromBody] IEnumerable <EmployeesAddDto> employeesAddDtos)
        {
            var employees = _mapper.Map <IEnumerable <Employee> >(employeesAddDtos);

            var result = await _service.AddRangeAsync(employees);

            if (result.ResultStatus == ResultStatus.Error)
            {
                return(BadRequest(new ErrorDto
                {
                    Message = ApiResultMessages.ResultMessage(false),
                    ResultStatus = result.ResultStatus
                }));
            }

            return(Created(string.Empty, employeesAddDtos));
        }
示例#19
0
        public IActionResult RemoveAll([FromBody] IEnumerable <EmployeeListDelete> employeeListDeletes)
        {
            var employeeList = _mapper.Map <IEnumerable <Employee> >(employeeListDeletes);

            var result = _service.DeleteRange(employeeList);

            if (result.ResultStatus == ResultStatus.Error)
            {
                return(BadRequest(new ErrorDto
                {
                    Message = ApiResultMessages.ResultMessage(false),
                    ResultStatus = result.ResultStatus
                }));
            }

            return(Ok(ApiResultMessages.ResultMessage(true)));
        }
示例#20
0
        public IActionResult Remove(int id)
        {
            var employee = _service.GetByIdAsync(id).Result;

            var result = _service.Delete(employee.Data);

            if (result.ResultStatus == ResultStatus.Error)
            {
                return(BadRequest(new ErrorDto
                {
                    Message = ApiResultMessages.ResultMessage(false),
                    ResultStatus = result.ResultStatus
                }));
            }

            return(Ok(ApiResultMessages.ResultMessage(true)));
        }
示例#21
0
        public async Task <IActionResult> GetAll()
        {
            var result = await _service.GetAllAsync();

            if (result.ResultStatus == ResultStatus.Error)
            {
                return(BadRequest(new ErrorDto
                {
                    Message = ApiResultMessages.ResultMessage(false),
                    ResultStatus = result.ResultStatus
                }));
            }

            return(Ok(new EmployeeListDto
            {
                Employees = result.Data,
                Message = ApiResultMessages.ResultMessage(true),
                ResultStatus = result.ResultStatus
            }));
        }
        public async Task <IActionResult> GetById(int id)
        {
            var result = await _service.GetByIdAsync(id);

            if (result.ResultStatus == ResultStatus.Error)
            {
                return(BadRequest(new ErrorDto
                {
                    Message = ApiResultMessages.ResultMessage(false),
                    ResultStatus = result.ResultStatus
                }));
            }

            return(Ok(new MemberCustomerDto
            {
                MemberCustomer = result.Data,
                Message = ApiResultMessages.ResultMessage(true),
                ResultStatus = result.ResultStatus
            }));
        }
        public IActionResult Update([FromBody] MemberCustomerUpdateDto memberCustomerUpdateDto)
        {
            var oldMemberCustomer = _service.GetByIdAsync(memberCustomerUpdateDto.Id).Result;

            var memberCustomerUpdate = _mapper.Map <MemberCustomerUpdateDto, MemberCustomer>(memberCustomerUpdateDto, oldMemberCustomer.Data);

            var result = _service.Update(memberCustomerUpdate);

            if (result.ResultStatus == ResultStatus.Error)
            {
                return(BadRequest(new ErrorDto
                {
                    Message = ApiResultMessages.ResultMessage(false),
                    ResultStatus = result.ResultStatus
                }));
            }

            return(Ok(new MemberCustomerDto
            {
                MemberCustomer = result.Data,
                Message = ApiResultMessages.ResultMessage(true),
                ResultStatus = result.ResultStatus
            }));
        }
示例#24
0
        public IActionResult Update([FromBody] EmployeeUpdateDto employeeUpdateDto)
        {
            var oldEmployee = _service.GetByIdAsync(employeeUpdateDto.Id).Result;

            var employeeUpdate = _mapper.Map <EmployeeUpdateDto, Employee>(employeeUpdateDto, oldEmployee.Data);

            var result = _service.Update(employeeUpdate);

            if (result.ResultStatus == ResultStatus.Error)
            {
                return(BadRequest(new ErrorDto
                {
                    Message = ApiResultMessages.ResultMessage(false),
                    ResultStatus = result.ResultStatus
                }));
            }

            return(Ok(new EmployeeDto
            {
                Employee = result.Data,
                Message = ApiResultMessages.ResultMessage(true),
                ResultStatus = result.ResultStatus
            }));
        }