예제 #1
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);
        }