示例#1
0
        public async Task <IActionResult> UpdateSupplier([FromBody] SupplierDataTransformation supplierDataTransformation)
        {
            SecurityModel securityModel = (SecurityModel)(HttpContext.Items["SecurityModel"]);

            int accountId = securityModel.AccountId;

            supplierDataTransformation.AccountId = accountId;

            ResponseModel <SupplierDataTransformation> returnResponse = new ResponseModel <SupplierDataTransformation>();

            try
            {
                returnResponse = await _purchaseOrderManagementBusinessService.UpdateSupplier(supplierDataTransformation);

                returnResponse.Token = securityModel.Token;
                if (returnResponse.ReturnStatus == false)
                {
                    return(BadRequest(returnResponse));
                }

                return(Ok(returnResponse));
            }
            catch (Exception ex)
            {
                returnResponse.ReturnStatus = false;
                returnResponse.ReturnMessage.Add(ex.Message);
                return(BadRequest(returnResponse));
            }
        }
示例#2
0
        /// <summary>
        /// Supplier Inquiry
        /// </summary>
        /// <param name="accountId"></param>
        /// <param name="supplierName"></param>
        /// <param name="currentPageNumber"></param>
        /// <param name="pageSize"></param>
        /// <param name="sortExpression"></param>
        /// <param name="sortDirection"></param>
        /// <returns></returns>
        public async Task <ResponseModel <List <SupplierDataTransformation> > > SupplierInquiry(int accountId, string supplierName, int currentPageNumber, int pageSize, string sortExpression, string sortDirection)
        {
            ResponseModel <List <SupplierDataTransformation> > returnResponse = new ResponseModel <List <SupplierDataTransformation> >();

            List <SupplierDataTransformation> suppliers = new List <SupplierDataTransformation>();

            try
            {
                _purchaseOrderManagementDataService.OpenConnection(_connectionStrings.PrimaryDatabaseConnectionString);

                DataGridPagingInformation dataGridPagingInformation = new DataGridPagingInformation();
                dataGridPagingInformation.CurrentPageNumber = currentPageNumber;
                dataGridPagingInformation.PageSize          = pageSize;
                dataGridPagingInformation.SortDirection     = sortDirection;
                dataGridPagingInformation.SortExpression    = sortExpression;

                List <Supplier> supplierList = await _purchaseOrderManagementDataService.SupplierInquiry(accountId, supplierName, dataGridPagingInformation);

                foreach (Supplier supplier in supplierList)
                {
                    SupplierDataTransformation supplierDataTransformation = new SupplierDataTransformation();
                    supplierDataTransformation.SupplierId   = supplier.SupplierId;
                    supplierDataTransformation.AddressLine1 = supplier.AddressLine1;
                    supplierDataTransformation.AddressLine2 = supplier.AddressLine2;
                    supplierDataTransformation.City         = supplier.City;
                    supplierDataTransformation.Region       = supplier.Region;
                    supplierDataTransformation.PostalCode   = supplier.PostalCode;
                    supplierDataTransformation.SupplierName = supplier.Name;
                    suppliers.Add(supplierDataTransformation);
                }

                returnResponse.Entity     = suppliers;
                returnResponse.TotalRows  = dataGridPagingInformation.TotalRows;
                returnResponse.TotalPages = dataGridPagingInformation.TotalPages;

                returnResponse.ReturnStatus = true;
            }
            catch (Exception ex)
            {
                _purchaseOrderManagementDataService.RollbackTransaction();
                returnResponse.ReturnStatus = false;
                returnResponse.ReturnMessage.Add(ex.Message);
            }
            finally
            {
                _purchaseOrderManagementDataService.CloseConnection();
            }

            return(returnResponse);
        }
示例#3
0
        /// <summary>
        /// Get Supplier Information
        /// </summary>
        /// <param name="accountId"></param>
        /// <param name="supplierId"></param>
        /// <returns></returns>
        public async Task <ResponseModel <SupplierDataTransformation> > GetSupplierInformation(int accountId, int supplierId)
        {
            ResponseModel <SupplierDataTransformation> returnResponse = new ResponseModel <SupplierDataTransformation>();
            SupplierDataTransformation supplierDataTransformation     = new SupplierDataTransformation();

            Supplier supplier = new Supplier();

            try
            {
                _purchaseOrderManagementDataService.OpenConnection(_connectionStrings.PrimaryDatabaseConnectionString);

                supplier = await _purchaseOrderManagementDataService.GetSupplierInformation(accountId, supplierId);

                supplierDataTransformation              = new SupplierDataTransformation();
                supplierDataTransformation.SupplierId   = supplier.SupplierId;
                supplierDataTransformation.AddressLine1 = supplier.AddressLine1;
                supplierDataTransformation.AddressLine2 = supplier.AddressLine2;
                supplierDataTransformation.City         = supplier.City;
                supplierDataTransformation.Region       = supplier.Region;
                supplierDataTransformation.PostalCode   = supplier.PostalCode;
                supplierDataTransformation.SupplierName = supplier.Name;

                returnResponse.ReturnStatus = true;
            }
            catch (Exception ex)
            {
                _purchaseOrderManagementDataService.RollbackTransaction();
                returnResponse.ReturnStatus = false;
                returnResponse.ReturnMessage.Add(ex.Message);
            }
            finally
            {
                _purchaseOrderManagementDataService.CloseConnection();
            }

            returnResponse.Entity = supplierDataTransformation;

            return(returnResponse);
        }
示例#4
0
        /// <summary>
        /// Update Supplier
        /// </summary>
        /// <param name="productDataTransformation"></param>
        /// <returns></returns>
        public async Task <ResponseModel <SupplierDataTransformation> > UpdateSupplier(SupplierDataTransformation supplierDataTransformation)
        {
            ResponseModel <SupplierDataTransformation> returnResponse = new ResponseModel <SupplierDataTransformation>();

            Supplier supplier = new Supplier();

            try
            {
                _purchaseOrderManagementDataService.OpenConnection(_connectionStrings.PrimaryDatabaseConnectionString);
                _purchaseOrderManagementDataService.BeginTransaction((int)IsolationLevel.Serializable);

                SupplierBusinessRules <SupplierDataTransformation> supplierBusinessRules = new SupplierBusinessRules <SupplierDataTransformation>(supplierDataTransformation, _purchaseOrderManagementDataService);
                ValidationResult validationResult = await supplierBusinessRules.Validate();

                if (validationResult.ValidationStatus == false)
                {
                    _purchaseOrderManagementDataService.RollbackTransaction();

                    returnResponse.ReturnMessage = validationResult.ValidationMessages;
                    returnResponse.ReturnStatus  = validationResult.ValidationStatus;

                    return(returnResponse);
                }

                int supplierId = supplierDataTransformation.SupplierId;
                int accountId  = supplierDataTransformation.AccountId;

                supplier = await _purchaseOrderManagementDataService.GetSupplierInformationForUpdate(accountId, supplierId);

                supplier.Name         = supplierDataTransformation.SupplierName;
                supplier.AddressLine1 = supplierDataTransformation.AddressLine1;
                supplier.AddressLine2 = supplierDataTransformation.AddressLine2;
                supplier.City         = supplierDataTransformation.City;
                supplier.Region       = supplierDataTransformation.Region;
                supplier.PostalCode   = supplierDataTransformation.PostalCode;

                await _purchaseOrderManagementDataService.UpdateSupplier(supplier);

                await _purchaseOrderManagementDataService.UpdateDatabase();

                _purchaseOrderManagementDataService.CommitTransaction();

                returnResponse.ReturnStatus = true;
            }
            catch (Exception ex)
            {
                _purchaseOrderManagementDataService.RollbackTransaction();
                returnResponse.ReturnStatus = false;
                returnResponse.ReturnMessage.Add(ex.Message);
            }
            finally
            {
                _purchaseOrderManagementDataService.CloseConnection();
            }

            returnResponse.Entity = supplierDataTransformation;

            return(returnResponse);
        }