Exemple #1
0
        public ServiceResult <ProductBase> CreateProduct(ProductBase product)
        {
            bool isProductValid;

            try
            {
                isProductValid = ValidateProductBase(product);
            }
            catch (ArgumentException aex)
            {
                return(ServiceResult <ProductBase> .CreateErrorResult(aex.Message));
            }

            if (!isProductValid)
            {
                return(ServiceResult <ProductBase> .CreateErrorResult("Model is not valid"));
            }

            try
            {
                var result = _productProvider.CreateBaseProduct(product);
                return(ServiceResult <ProductBase> .CreateSuccessResult(result));
            }
            catch (Exception ex)
            {
                return(ServiceResult <ProductBase> .CreateErrorResult(ex.Message));
            }
        }
Exemple #2
0
        public ServiceResult <bool> UpdateProduct(int productId, ProductBase product)
        {
            if (productId < 1)
            {
                return(ServiceResult <bool> .CreateErrorResult($"{nameof(productId)} must be more than 0"));
            }

            bool isProductValid;

            try
            {
                isProductValid = ValidateProductBase(product);
            }
            catch (ArgumentException aex)
            {
                return(ServiceResult <bool> .CreateErrorResult(aex.Message));
            }

            if (!isProductValid)
            {
                return(ServiceResult <bool> .CreateErrorResult("Model is not valid"));
            }

            try
            {
                var result = _productProvider.UpdateBaseProduct(productId, product);
                return(ServiceResult <bool> .CreateSuccessResult(result));
            }
            catch (Exception ex)
            {
                return(ServiceResult <bool> .CreateErrorResult(ex.Message));
            }
        }
        public void ServiceResult_CreateErrorResult(string message)
        {
            ServiceResult <object> result = null;

            Assert.DoesNotThrow(() => result = ServiceResult <object> .CreateErrorResult(message));
            Assert.IsNotNull(result);
            Assert.IsTrue(result.IsErrored);
            Assert.AreEqual(message, result.ErrorMessage);
        }
Exemple #4
0
        public ServiceResult <IList <Company> > GetCompaniesForProduct(int baseProductId)
        {
            if (baseProductId <= 0)
            {
                return(ServiceResult <IList <Company> > .CreateErrorResult("BaseProductId must be more than 0"));
            }

            var result = _companyProvider.GetCompaniesFor(baseProductId);

            return(ServiceResult <IList <Company> > .CreateSuccessResult(result));
        }
Exemple #5
0
        public ServiceResult <Company> Get(int id)
        {
            if (id <= 0)
            {
                return(ServiceResult <Company> .CreateErrorResult("Id must be great than 0"));
            }

            var result = _companyProvider.GetCompany(id);

            return(ServiceResult <Company> .CreateSuccessResult(result));
        }
Exemple #6
0
        public ServiceResult <bool> DeleteCompany(int id)
        {
            if (id <= 0)
            {
                return(ServiceResult <bool> .CreateErrorResult($"{nameof(id)} can not be less than 1"));
            }

            var result = _companyProvider.DeleteCompany(id);

            return(ServiceResult <bool> .CreateSuccessResult(result));
        }
        public void ServiceResult_AppendErrorMessage_InitialErrorResult_AddErrorMessage(string error1, string error2)
        {
            var initialResult = ServiceResult <object> .CreateErrorResult(error1);

            ServiceResult <object> result = null;

            Assert.DoesNotThrow(() => result = initialResult.AppendErrorMessage(error2));
            Assert.IsNotNull(result);
            Assert.IsTrue(result.IsErrored);
            Assert.AreEqual($"{error1}\n{error2}", result.ErrorMessage);
        }
Exemple #8
0
        public ServiceResult <IList <Company> > GetCompanies(PageRequest pageInfo)
        {
            string errorMessage;
            var    isValid = ValidatePageRequest(pageInfo, out errorMessage);

            if (!isValid)
            {
                return(ServiceResult <IList <Company> > .CreateErrorResult(errorMessage));
            }

            var result = _companyProvider.GetCompanies(pageInfo);

            return(ServiceResult <IList <Company> > .CreateSuccessResult(result));
        }
Exemple #9
0
        public ServiceResult <IList <Product> > GetProductsByCompany(int companyId)
        {
            if (companyId < 1)
            {
                return(ServiceResult <IList <Product> > .CreateErrorResult($"{nameof(companyId)} must be more than 0"));
            }

            try
            {
                var result = _productProvider.GetByCompany(companyId);
                return(ServiceResult <IList <Product> > .CreateSuccessResult(result));
            }
            catch (Exception ex)
            {
                return(ServiceResult <IList <Product> > .CreateErrorResult(ex.Message));
            }
        }
Exemple #10
0
        public ServiceResult <IList <ProductBase> > GetProductsBase(int count, int page)
        {
            if (count < 1 || page < 1)
            {
                return(ServiceResult <IList <ProductBase> > .CreateErrorResult($"{nameof(count)} and {nameof(page)} must be more than 0"));
            }

            try
            {
                var result = _productProvider.GetProductsBase(count, page);
                return(ServiceResult <IList <ProductBase> > .CreateSuccessResult(result));
            }
            catch (Exception ex)
            {
                return(ServiceResult <IList <ProductBase> > .CreateErrorResult(ex.Message));
            }
        }
Exemple #11
0
        public ServiceResult <Product> GetProductById(int id)
        {
            if (id < 1)
            {
                return(ServiceResult <Product> .CreateErrorResult($"{nameof(id)} must be more than 0"));
            }

            try
            {
                var result = _productProvider.GetById(id);
                return(ServiceResult <Product> .CreateSuccessResult(result));
            }
            catch (Exception ex)
            {
                return(ServiceResult <Product> .CreateErrorResult(ex.Message));
            }
        }
Exemple #12
0
        public ServiceResult <bool> DeleteProduct(int productId)
        {
            if (productId < 1)
            {
                return(ServiceResult <bool> .CreateErrorResult($"{nameof(productId)} must be more than 0"));
            }

            try
            {
                var result = _productProvider.DeleteBaseProduct(productId);
                return(ServiceResult <bool> .CreateSuccessResult(result));
            }
            catch (Exception ex)
            {
                return(ServiceResult <bool> .CreateErrorResult(ex.Message));
            }
        }
Exemple #13
0
        public ServiceResult <bool> UpdateCompany(Company company)
        {
            if (company == null)
            {
                return(ServiceResult <bool> .CreateErrorResult($"{nameof(company)} can not be null"));
            }
            if (company.Id <= 0)
            {
                return(ServiceResult <bool> .CreateErrorResult($"{nameof(company.Id)} can not be less than 1"));
            }
            if (String.IsNullOrWhiteSpace(company.Name))
            {
                return(ServiceResult <bool> .CreateErrorResult($"{nameof(company.Name)} is required"));
            }

            var result = _companyProvider.UpdateCompany(company);

            return(ServiceResult <bool> .CreateSuccessResult(result));
        }
Exemple #14
0
        public ServiceResult <Company> CreateCompany(Company company)
        {
            if (company == null)
            {
                return(ServiceResult <Company> .CreateErrorResult("Company cannot be null"));
            }
            if (String.IsNullOrWhiteSpace(company.Name))
            {
                return(ServiceResult <Company> .CreateErrorResult("Name is required"));
            }

            var result = _companyProvider.CreateCompany(company);

            if (result != null)
            {
                return(ServiceResult <Company> .CreateSuccessResult(result));
            }
            return(ServiceResult <Company> .CreateErrorResult("Error creating Company"));
        }