Пример #1
0
        private BusinessPartnerResponse ParseCustomerQuery(CustomerResponseMessage_sync sapResponse)
        {
            BusinessPartnerResponse response = new BusinessPartnerResponse();
            BaseResponse            tempRes  = SapLogParser.ParseSapResponseLog(sapResponse.Log);

            response.Errors   = tempRes.Errors;
            response.Warnings = tempRes.Warnings;

            if (sapResponse.Customer != null)
            {
                response.BpExternalId    = sapResponse.Customer[0].InternalID;
                response.CustomerDetails = new AccountTypeDetails();

                if (sapResponse.Customer[0].SalesArrangement != null)
                {
                    response.CustomerDetails.CurrencyID    = sapResponse.Customer[0].SalesArrangement[0].CurrencyCode;
                    response.CustomerDetails.PaymentTermID = sapResponse.Customer[0].SalesArrangement[0].CashDiscountTermsCode != null ?
                                                             sapResponse.Customer[0].SalesArrangement[0].CashDiscountTermsCode.Value : null;

                    if (sapResponse.Customer[0].PaymentData != null && sapResponse.Customer[0].PaymentData[0].CreditLimitAmount != null)
                    {
                        response.CustomerDetails.CreditLimit = sapResponse.Customer[0].PaymentData[0].CreditLimitAmount.Value;
                    }
                }
            }

            return(response);
        }
Пример #2
0
        private BusinessPartnerResponse CreateSetSupplierResponse(SupplierBundleMaintainConfirmationMessage_sync_V1 sapResponse)
        {
            BusinessPartnerResponse response = new BusinessPartnerResponse();
            BaseResponse            tempRes  = SapLogParser.ParseSapResponseLog(sapResponse.Log);

            response.Errors   = tempRes.Errors;
            response.Warnings = tempRes.Warnings;

            if (sapResponse.Supplier != null)
            {
                var getAllDetails = CreateSupplierQuery(sapResponse.Supplier[0].InternalID);

                if (getAllDetails.Supplier != null)
                {
                    response.BpExternalId = getAllDetails.Supplier[0].InternalID;

                    if (getAllDetails.Supplier[0].PurchasingData != null)
                    {
                        response.SupplierDetails               = new AccountTypeDetails();
                        response.SupplierDetails.CurrencyID    = getAllDetails.Supplier[0].PurchasingData.PurchaseOrderCurrencyCode;
                        response.SupplierDetails.PaymentTermID = getAllDetails.Supplier[0].PurchasingData.CashDiscountTermsCode != null ?
                                                                 getAllDetails.Supplier[0].PurchasingData.CashDiscountTermsCode.Value : null;
                    }
                }
            }

            return(response);
        }
Пример #3
0
        public BusinessPartnerResponse Put(UpdateBusinessPartner request)
        {
            try
            {
                BusinessPartnerModel bpModel     = request.ConvertTo <BusinessPartnerModel>();
                var replaceResult                = businessPartnerRepository.Upsert(bpModel);
                BusinessPartnerResponse response = bpModel.ConvertTo <BusinessPartnerResponse>();

                if (!replaceResult.IsAcknowledged)
                {
                    Log.Error($"Upsert operation was not Acknowledged for BusinessPartner with Id:{request.Id} Name:{request.Name}.");
                    throw new Exception($"Upsert operation was not Acknowledged for BusinessPartner with Id:{request.Id} Name:{request.Name}.");
                }

                if (replaceResult.UpsertedId != null)
                {
                    response.Id = replaceResult.UpsertedId.AsGuid;
                }

                return(response);
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Something went wrong while upserting BusinessPartner.");
                throw;
            }
        }
Пример #4
0
        public BusinessPartnerResponse Create(BusinessPartnerViewModel businessPartner)
        {
            BusinessPartnerResponse response = new BusinessPartnerResponse();

            using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db"))
            {
                db.Open();

                SqliteCommand insertCommand = db.CreateCommand();
                insertCommand.CommandText = SqlCommandInsertPart;

                try
                {
                    insertCommand = AddCreateParameters(insertCommand, businessPartner);
                    insertCommand.ExecuteNonQuery();
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage = error.Message;
                    response.Success        = false;
                    response.Message        = error.Message;
                    return(response);
                }
                db.Close();

                response.Success = true;
                return(response);
            }
        }
Пример #5
0
        public BusinessPartnerResponse Delete(Guid identifier)
        {
            BusinessPartnerResponse response = new BusinessPartnerResponse();

            using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db"))
            {
                db.Open();

                SqliteCommand insertCommand = new SqliteCommand();
                insertCommand.Connection = db;

                //Use parameterized query to prevent SQL injection attacks
                insertCommand.CommandText =
                    "DELETE FROM BusinessPartners WHERE Identifier = @Identifier";
                insertCommand.Parameters.AddWithValue("@Identifier", identifier);
                try
                {
                    insertCommand.ExecuteReader();
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage = error.Message;
                    response.Success        = false;
                    response.Message        = error.Message;
                    return(response);
                }
                db.Close();

                response.Success = true;
                return(response);
            }
        }
Пример #6
0
        private BusinessPartnerResponse CreateSetCustomerResponse(CustomerBundleMaintainConfirmationMessage_sync_V1 sapResponse)
        {
            BusinessPartnerResponse response = new BusinessPartnerResponse();
            BaseResponse            tempRes  = SapLogParser.ParseSapResponseLog(sapResponse.Log);

            response.Errors   = tempRes.Errors;
            response.Warnings = tempRes.Warnings;

            if (sapResponse.Customer != null)
            {
                var getAllDetails = CreateCustomerQuery(sapResponse.Customer[0].InternalID);

                if (getAllDetails.Customer != null)
                {
                    response.BpExternalId = getAllDetails.Customer[0].InternalID;

                    if (getAllDetails.Customer[0].SalesArrangement != null)
                    {
                        response.CustomerDetails               = new AccountTypeDetails();
                        response.CustomerDetails.CurrencyID    = getAllDetails.Customer[0].SalesArrangement[0].CurrencyCode;
                        response.CustomerDetails.PaymentTermID = getAllDetails.Customer[0].SalesArrangement[0].CashDiscountTermsCode != null ?
                                                                 getAllDetails.Customer[0].SalesArrangement[0].CashDiscountTermsCode.Value : null;

                        if (getAllDetails.Customer[0].PaymentData != null && getAllDetails.Customer[0].PaymentData[0].CreditLimitAmount != null)
                        {
                            response.CustomerDetails.CreditLimit = getAllDetails.Customer[0].PaymentData[0].CreditLimitAmount.Value;
                        }
                    }
                }
            }

            return(response);
        }
Пример #7
0
        public BusinessPartnerIncomingResponse MapBusinessPartnerResponse(BusinessPartnerResponse bpr)
        {
            //var response = new BusinessPartnerIncomingResponse();
            if (bpr.Errors.Count > 0)
            {
                return new BusinessPartnerIncomingResponse {
                           Errors = bpr.Errors
                }
            }
            ;

            var response = GetBusinessPartnerForIncoming(bpr.BpExternalId);

            response.ExternalId = bpr.ExternalId;

            foreach (var contact in response.Contacts)
            {
                contact.ContactId = bpr.ContactExternalIds.Where(x => x.ExternalId == contact.ExternalId).First().LocalId;
            }

            foreach (var location in response.Locations)
            {
                location.LocationId = bpr.LocationExternalIds.Where(x => x.ExternalId == location.ExternalId).First().LocalId;
            }

            //Copying the Parent GroupId
            bpr.Hierarchy.ParentGroupId       = response.AccountDetails.Hierarchy.ParentGroupId;
            response.AccountDetails.Hierarchy = bpr.Hierarchy;

            return(response);
        }
Пример #8
0
        private BusinessPartnerResponse SetCustomerData(string externalId, BusinessPartnerRequest businessPartner)
        {
            var response = new BusinessPartnerResponse();

            response = _customerService.SetCustomerFromBusinessPartner(businessPartner, _billingCountry, externalId);

            if (response.Errors.Count > 0)
            {
                return(response);
            }

            AccountHierarchyResponse hierResponse = new AccountHierarchyResponse();

            if (string.IsNullOrEmpty(businessPartner.BpDetails.Hierarchy.ParentId))
            {
                hierResponse = _hierarchyService.SetAccountHierarchy(businessPartner.BpDetails.Hierarchy, externalId);
            }
            else
            {
                hierResponse = _hierarchyService.SetAccountToGroup(businessPartner.BpDetails.Hierarchy, externalId);
            }

            response.Errors    = hierResponse.Errors;
            response.Warnings  = hierResponse.Warnings;
            response.Note      = hierResponse.Note;
            response.Hierarchy = hierResponse;

            return(response);
        }
Пример #9
0
        private BusinessPartnerQueryResponse ParseSapQueryResponse(BusinessPartnerResponseMessage_sync sapResponse, BusinessPartnerRequest bpRequest)
        {
            BusinessPartnerQueryResponse response = new BusinessPartnerQueryResponse();
            BaseResponse tempRes = SapLogParser.ParseSapResponseLog(sapResponse.Log);

            response.Errors   = tempRes.Errors;
            response.Warnings = tempRes.Warnings;

            if (sapResponse.BusinessPartner != null)
            {
                response.BpExternalId = sapResponse.BusinessPartner[0].InternalID;
                response.IsSupplier   = sapResponse.BusinessPartner[0].SupplierIndicator;
                response.IsCustomer   = sapResponse.BusinessPartner[0].CustomerIndicator;
                response.Status       = sapResponse.BusinessPartner[0].LifeCycleStatusCode.GetEnumDescription();
            }
            else
            {
                return(response);
            }

            BusinessPartnerResponse conAndLocData = SetLocationAndContactIds(sapResponse, bpRequest);

            response.LocationExternalIds = conAndLocData.LocationExternalIds;
            response.ContactExternalIds  = conAndLocData.ContactExternalIds;

            return(response);
        }
Пример #10
0
        public async Task <IActionResult> CreateBusinesspartner([FromBody] CreateBusinesspartnerRequest createBusinesspartnerRequest)
        {
            IActionResult result;

            _logger.LogInformation($"CreateBusinesspartner({nameof(CreateBusinesspartnerRequest)}: {createBusinesspartnerRequest.ToJson()})");

            try
            {
                var resp = await _moveInLogic.CreateBusinessPartner(createBusinesspartnerRequest);

                if (resp.HttpStatusCode == System.Net.HttpStatusCode.BadRequest)
                {
                    return(BadRequest());
                }
                var createBp = new BusinessPartnerResponse()
                {
                    BpId = resp.BpId
                };
                result = Ok(createBp);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Unable to create BP for a customer", ex.Message);

                result = ex.ToActionResult();
            }

            return(result);
        }
Пример #11
0
        public BusinessPartnerResponse GetBusinessPartner(Guid identifier)
        {
            BusinessPartnerResponse  response        = new BusinessPartnerResponse();
            BusinessPartnerViewModel BusinessPartner = new BusinessPartnerViewModel();

            using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db"))
            {
                db.Open();
                try
                {
                    SqliteCommand selectCommand = new SqliteCommand(
                        SqlCommandSelectPart +
                        "FROM BusinessPartners " +
                        "WHERE Identifier = @Identifier;", db);
                    selectCommand.Parameters.AddWithValue("@Identifier", identifier);

                    SqliteDataReader query = selectCommand.ExecuteReader();

                    if (query.Read())
                    {
                        int counter = 0;
                        BusinessPartnerViewModel dbEntry = new BusinessPartnerViewModel();
                        dbEntry.Id                = SQLiteHelper.GetInt(query, ref counter);
                        dbEntry.Identifier        = SQLiteHelper.GetGuid(query, ref counter);
                        dbEntry.Code              = SQLiteHelper.GetString(query, ref counter);
                        dbEntry.Name              = SQLiteHelper.GetString(query, ref counter);
                        dbEntry.Director          = SQLiteHelper.GetString(query, ref counter);
                        dbEntry.Address           = SQLiteHelper.GetString(query, ref counter);
                        dbEntry.InoAddress        = SQLiteHelper.GetString(query, ref counter);
                        dbEntry.PIB               = SQLiteHelper.GetString(query, ref counter);
                        dbEntry.MatCode           = SQLiteHelper.GetString(query, ref counter);
                        dbEntry.Mobile            = SQLiteHelper.GetString(query, ref counter);
                        dbEntry.Phone             = SQLiteHelper.GetString(query, ref counter);
                        dbEntry.Email             = SQLiteHelper.GetString(query, ref counter);
                        dbEntry.ActivityCode      = SQLiteHelper.GetString(query, ref counter);
                        dbEntry.BankAccountNumber = SQLiteHelper.GetString(query, ref counter);
                        dbEntry.OpeningDate       = SQLiteHelper.GetDateTime(query, ref counter);
                        dbEntry.BranchOpeningDate = SQLiteHelper.GetDateTime(query, ref counter);
                        dbEntry.IsSynced          = SQLiteHelper.GetBoolean(query, ref counter);
                        dbEntry.UpdatedAt         = SQLiteHelper.GetDateTime(query, ref counter);
                        dbEntry.CreatedBy         = SQLiteHelper.GetCreatedBy(query, ref counter);
                        dbEntry.Company           = SQLiteHelper.GetCompany(query, ref counter);
                        BusinessPartner           = dbEntry;
                    }
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage  = error.Message;
                    response.Success         = false;
                    response.Message         = error.Message;
                    response.BusinessPartner = new BusinessPartnerViewModel();
                    return(response);
                }
                db.Close();
            }
            response.Success         = true;
            response.BusinessPartner = BusinessPartner;
            return(response);
        }
Пример #12
0
        public void OneTimeSetUp()
        {
            var service = appHost.Container.Resolve <BusinessPartnerService>();

            starbucksBPResponse = service.Post(starbucksBP);
            geBPResponse        = service.Post(geBP);
            lufthansaBPResponse = service.Post(lufthansaBP);
            microsoftBPResponse = service.Post(microsoftBP);
        }
Пример #13
0
        public void OneTimeSetUp()
        {

            var bpService = appHost.Container.Resolve<BusinessPartnerService>();
            starbucksBPResponse = bpService.Post(starbucksBP);

            var poService = appHost.Container.Resolve<PurchaseOrderService>();
            coffeePO.CustomerId = starbucksBPResponse.Id;
            coffeePOResponse = poService.Post(coffeePO);
        }
Пример #14
0
        public BusinessPartnerResponse ProcessBusinessPartnerRequest(BusinessPartnerRequest businessPartner)
        {
            var bpManageResponse = SetBusinessPartner(businessPartner);
            var response         = new BusinessPartnerResponse();

            if (bpManageResponse.Errors.Count > 0)
            {
                return(bpManageResponse);
            }

            var bpQueryResponse = GetBusinessPartner(bpManageResponse.BpExternalId, businessPartner);

            if (string.IsNullOrEmpty(bpQueryResponse.BpExternalId))
            {
                return(bpQueryResponse);
            }


            if (businessPartner.BpDetails.AccountTypes.Contains("supplier", StringComparer.OrdinalIgnoreCase))
            {
                var suppRequest = SetSupplierData(bpQueryResponse.BpExternalId);
                response.SupplierDetails = suppRequest.SupplierDetails;

                if (suppRequest.Errors.Count > 0)
                {
                    return(suppRequest);
                }
            }

            if (businessPartner.BpDetails.AccountTypes.Contains("customer", StringComparer.OrdinalIgnoreCase))
            {
                var custRequest = SetCustomerData(bpQueryResponse.BpExternalId, businessPartner);

                if (custRequest.Errors.Count > 0)
                {
                    return(custRequest);
                }

                response.Hierarchy       = custRequest.Hierarchy;
                response.Hierarchy.Id    = businessPartner.BpDetails.Hierarchy.Id;
                response.CustomerDetails = custRequest.CustomerDetails;
            }

            response.BpExternalId        = bpQueryResponse.BpExternalId;
            response.ExternalId          = bpQueryResponse.BpExternalId;
            response.ContactExternalIds  = bpQueryResponse.ContactExternalIds;
            response.LocationExternalIds = bpQueryResponse.LocationExternalIds;
            response.Status   = bpQueryResponse.Status;
            response.Errors   = bpQueryResponse.Errors;
            response.Warnings = bpQueryResponse.Warnings;
            response.Note     = bpQueryResponse.Note;

            return(response);
        }
Пример #15
0
        public void OneTimeSetUp()
        {
            var bpService = appHost.Container.Resolve <BusinessPartnerService>();

            starbucksBPResponse = bpService.Post(starbucksBP);
            microsoftBPResponse = bpService.Post(microsoftBP);

            var invoiceService = appHost.Container.Resolve <InvoiceService>();

            softwareInvoice.CustomerId = starbucksBPResponse.Id;
            softwareInvoice.VendorId   = microsoftBPResponse.Id;
            softwareInvoiceResponse    = invoiceService.Post(softwareInvoice);
        }
Пример #16
0
        public BusinessPartnerResponse SetLocationAndContactIds(BusinessPartnerResponseMessage_sync queryResponse, BusinessPartnerRequest bpRequest)
        {
            var response = new BusinessPartnerResponse();

            if (queryResponse.BusinessPartner[0].AddressInformation != null)
            {
                response.LocationExternalIds = new List <PairedIdsResponse>();

                foreach (var location in bpRequest.Locations)
                {
                    var match = queryResponse.BusinessPartner[0].AddressInformation.FirstOrDefault(x => FindLocationMatch(x, location));

                    if (match != null)
                    {
                        response.LocationExternalIds.Add(new PairedIdsResponse
                        {
                            LocalId    = location.LocationId,
                            ExternalId = match.UUID.Value
                        });
                    }
                }
            }

            if (queryResponse.BusinessPartner[0].ContactPerson != null)
            {
                response.ContactExternalIds = new List <PairedIdsResponse>();

                foreach (var contact in bpRequest.Contacts)
                {
                    try
                    {
                        var match = queryResponse.BusinessPartner[0].ContactPerson.First(x => FindContactMatch(x, contact));

                        response.ContactExternalIds.Add(new PairedIdsResponse
                        {
                            LocalId    = contact.ContactId,
                            ExternalId = match.BusinessPartnerContactInternalID
                        });
                    }
                    catch (Exception e)
                    {
                        response.Errors.Add(e.Message);
                        return(response);
                    }
                }
            }

            return(response);
        }
Пример #17
0
        private BusinessPartnerResponse ParseSapManageResponse(BusinessPartnerBundleMaintainConfirmationMessage_sync sapResponse)
        {
            BusinessPartnerResponse response = new BusinessPartnerResponse();
            BaseResponse            tempRes  = SapLogParser.ParseSapResponseLog(sapResponse.Log);

            response.Errors   = tempRes.Errors;
            response.Warnings = tempRes.Warnings;

            if (sapResponse.BusinessPartner != null)
            {
                response.BpExternalId = sapResponse.BusinessPartner[0].InternalID;
            }

            return(response);
        }
        public BusinessPartnerResponse Create(BusinessPartnerViewModel businessPartnerViewModel)
        {
            BusinessPartnerResponse response = new BusinessPartnerResponse();

            try
            {
                response = WpfApiHandler.SendToApi <BusinessPartnerViewModel, BusinessPartnerResponse>(businessPartnerViewModel, "Create");
            }
            catch (Exception ex)
            {
                response.BusinessPartner = new BusinessPartnerViewModel();
                response.Success         = false;
                response.Message         = ex.Message;
            }
            return(response);
        }
        private void BtnSubmit_Click(object sender, RoutedEventArgs e)
        {
            #region Validation

            if (BusinessPartnerPhonesFromDB == null || BusinessPartnerPhonesFromDB.Count == 0)
            {
                MainWindow.WarningMessage = ((string)Application.Current.FindResource("Morate_uneti_osnovne_podatkeUzvičnik"));
                return;
            }

            #endregion

            Thread td = new Thread(() => {
                SubmitButtonContent = ((string)Application.Current.FindResource("Čuvanje_u_tokuTriTacke"));
                SubmitButtonEnabled = false;

                CurrentBusinessPartner.Phones    = BusinessPartnerPhonesFromDB;
                BusinessPartnerResponse response = businessPartnerService.Create(CurrentBusinessPartner);
                if (!response.Success)
                {
                    MainWindow.ErrorMessage = ((string)Application.Current.FindResource("Greška_kod_čuvanja_na_serveruUzvičnik"));
                    SubmitButtonContent     = ((string)Application.Current.FindResource("Proknjiži"));
                    SubmitButtonEnabled     = true;
                }

                if (response.Success)
                {
                    MainWindow.SuccessMessage = ((string)Application.Current.FindResource("Podaci_su_uspešno_sačuvaniUzvičnik"));
                    SubmitButtonContent       = ((string)Application.Current.FindResource("Proknjiži"));
                    SubmitButtonEnabled       = true;

                    BusinessPartnerCreatedUpdated();

                    Application.Current.Dispatcher.BeginInvoke(
                        System.Windows.Threading.DispatcherPriority.Normal,
                        new Action(() =>
                    {
                        FlyoutHelper.CloseFlyout(this);
                    })
                        );
                }
            });
            td.IsBackground = true;
            td.Start();
        }
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            if (CurrentBusinessPartner == null)
            {
                MainWindow.WarningMessage = "Morate odabrati firmu za brisanje!";
                return;
            }

            SirmiumERPVisualEffects.AddEffectOnDialogShow(this);

            // Create confirmation window
            DeleteConfirmation deleteConfirmationForm = new DeleteConfirmation("firma", CurrentBusinessPartner.Name + CurrentBusinessPartner.Code);
            var showDialog = deleteConfirmationForm.ShowDialog();

            if (showDialog != null && showDialog.Value)
            {
                BusinessPartnerResponse response = businessPartnerService.Delete(CurrentBusinessPartner.Identifier);
                if (!response.Success)
                {
                    MainWindow.ErrorMessage = "Greška kod brisanja sa servera!";
                    SirmiumERPVisualEffects.RemoveEffectOnDialogShow(this);
                    return;
                }

                response = new BusinessPartnerSQLiteRepository().Delete(CurrentBusinessPartner.Identifier);
                if (!response.Success)
                {
                    MainWindow.ErrorMessage = "Greška kod lokalnog brisanja!";
                    SirmiumERPVisualEffects.RemoveEffectOnDialogShow(this);
                    return;
                }

                MainWindow.SuccessMessage = "Firma je uspešno obrisana!";

                Thread displayThread = new Thread(() => PopulateData());
                displayThread.IsBackground = true;
                displayThread.Start();
            }

            // Remove blur effects
            SirmiumERPVisualEffects.RemoveEffectOnDialogShow(this);

            dgBusinessPartners.Focus();
        }
        public BusinessPartnerResponse Delete(Guid identifier)
        {
            BusinessPartnerResponse response = new BusinessPartnerResponse();

            try
            {
                BusinessPartnerViewModel viewModel = new BusinessPartnerViewModel();
                viewModel.Identifier = identifier;
                response             = WpfApiHandler.SendToApi <BusinessPartnerViewModel, BusinessPartnerResponse>(viewModel, "Delete");
            }
            catch (Exception ex)
            {
                response.BusinessPartner = new BusinessPartnerViewModel();
                response.Success         = false;
                response.Message         = ex.Message;
            }

            return(response);
        }
Пример #22
0
        public JsonResult Delete([FromBody] BusinessPartnerViewModel c)
        {
            BusinessPartnerResponse response = new BusinessPartnerResponse();

            try
            {
                response = this.businessPartnerService.Delete(c.Identifier);
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
                Console.WriteLine(ex.Message);
            }

            return(Json(response, new Newtonsoft.Json.JsonSerializerSettings()
            {
                Formatting = Newtonsoft.Json.Formatting.Indented
            }));
        }
        public BusinessPartnerResponse Create(BusinessPartnerViewModel businessPartner)
        {
            BusinessPartnerResponse response = new BusinessPartnerResponse();

            try
            {
                BusinessPartner addedBusinessPartner = unitOfWork.GetBusinessPartnerRepository().Create(businessPartner.ConvertToBusinessPartner());
                unitOfWork.Save();
                response.BusinessPartner = addedBusinessPartner.ConvertToBusinessPartnerViewModel();
                response.Success         = true;
            }
            catch (Exception ex)
            {
                response.BusinessPartner = new BusinessPartnerViewModel();
                response.Success         = false;
                response.Message         = ex.Message;
            }

            return(response);
        }
Пример #24
0
        public BusinessPartnerResponse DeleteAll()
        {
            BusinessPartnerResponse response = new BusinessPartnerResponse();

            try
            {
                using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db"))
                {
                    db.Open();
                    db.EnableExtensions(true);

                    SqliteCommand insertCommand = new SqliteCommand();
                    insertCommand.Connection = db;

                    //Use parameterized query to prevent SQL injection attacks
                    insertCommand.CommandText = "DELETE FROM BusinessPartners";
                    try
                    {
                        insertCommand.ExecuteReader();
                    }
                    catch (SqliteException error)
                    {
                        response.Success = false;
                        response.Message = error.Message;

                        MainWindow.ErrorMessage = error.Message;
                        return(response);
                    }
                    db.Close();
                }
            }
            catch (SqliteException error)
            {
                response.Success = false;
                response.Message = error.Message;
                return(response);
            }

            response.Success = true;
            return(response);
        }
Пример #25
0
        public BusinessPartnerResponse Create(BusinessPartnerViewModel businessPartner)
        {
            BusinessPartnerResponse response = new BusinessPartnerResponse();

            using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db"))
            {
                db.Open();

                SqliteCommand insertCommand = new SqliteCommand();
                insertCommand.Connection = db;

                //Use parameterized query to prevent SQL injection attacks
                insertCommand.CommandText = SqlCommandInsertPart;

                insertCommand.Parameters.AddWithValue("@ServerId", businessPartner.Id);
                insertCommand.Parameters.AddWithValue("@Identifier", businessPartner.Identifier);
                insertCommand.Parameters.AddWithValue("@Code", businessPartner.Code);
                insertCommand.Parameters.AddWithValue("@Name", ((object)businessPartner.Name) ?? DBNull.Value);
                insertCommand.Parameters.AddWithValue("@IsSynced", businessPartner.IsSynced);
                insertCommand.Parameters.AddWithValue("@UpdatedAt", businessPartner.UpdatedAt);
                insertCommand.Parameters.AddWithValue("@CreatedById", MainWindow.CurrentUser.Id);
                insertCommand.Parameters.AddWithValue("@CreatedByName", MainWindow.CurrentUser.FirstName + " " + MainWindow.CurrentUser.LastName);

                try
                {
                    insertCommand.ExecuteReader();
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage = error.Message;
                    response.Success        = false;
                    response.Message        = error.Message;
                    return(response);
                }
                db.Close();

                response.Success = true;
                return(response);
            }
        }
        public BusinessPartnerResponse Delete(Guid identifier)
        {
            BusinessPartnerResponse response = new BusinessPartnerResponse();

            try
            {
                BusinessPartner deletedBusinessPartner = unitOfWork.GetBusinessPartnerRepository().Delete(identifier);

                unitOfWork.Save();

                response.BusinessPartner = deletedBusinessPartner.ConvertToBusinessPartnerViewModel();
                response.Success         = true;
            }
            catch (Exception ex)
            {
                response.BusinessPartner = new BusinessPartnerViewModel();
                response.Success         = false;
                response.Message         = ex.Message;
            }

            return(response);
        }
Пример #27
0
        public BusinessPartnerResponse GetBusinessPartner(Guid identifier)
        {
            BusinessPartnerResponse  response        = new BusinessPartnerResponse();
            BusinessPartnerViewModel businessPartner = new BusinessPartnerViewModel();

            using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db"))
            {
                db.Open();
                try
                {
                    SqliteCommand selectCommand = new SqliteCommand(
                        SqlCommandSelectPart +
                        "FROM BusinessPartners " +
                        "WHERE Identifier = @Identifier;", db);
                    selectCommand.Parameters.AddWithValue("@Identifier", identifier);

                    SqliteDataReader query = selectCommand.ExecuteReader();

                    if (query.Read())
                    {
                        BusinessPartnerViewModel dbEntry = Read(query);

                        businessPartner = dbEntry;
                    }
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage  = error.Message;
                    response.Success         = false;
                    response.Message         = error.Message;
                    response.BusinessPartner = new BusinessPartnerViewModel();
                    return(response);
                }
                db.Close();
            }
            response.Success         = true;
            response.BusinessPartner = businessPartner;
            return(response);
        }
Пример #28
0
        private BusinessPartnerResponse ParseSupplierQuery(SupplierByElementsResponseMessage sapResponse)
        {
            BusinessPartnerResponse response = new BusinessPartnerResponse();
            BaseResponse            tempRes  = SapLogParser.ParseSapResponseLog(sapResponse.Log);

            response.Errors   = tempRes.Errors;
            response.Warnings = tempRes.Warnings;

            if (sapResponse.Supplier != null)
            {
                response.BpExternalId    = sapResponse.Supplier[0].InternalID;
                response.SupplierDetails = new AccountTypeDetails();

                if (sapResponse.Supplier[0].PurchasingData != null)
                {
                    response.SupplierDetails.CurrencyID    = sapResponse.Supplier[0].PurchasingData.PurchaseOrderCurrencyCode;
                    response.SupplierDetails.PaymentTermID = sapResponse.Supplier[0].PurchasingData.CashDiscountTermsCode != null ?
                                                             sapResponse.Supplier[0].PurchasingData.CashDiscountTermsCode.Value : null;
                }
            }

            return(response);
        }
Пример #29
0
        public BusinessPartnerResponse UpdateSyncStatus(Guid identifier, int serverId, bool isSynced)
        {
            BusinessPartnerResponse response = new BusinessPartnerResponse();

            using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db"))
            {
                db.Open();

                SqliteCommand insertCommand = new SqliteCommand();
                insertCommand.Connection = db;

                insertCommand.CommandText = "UPDATE BusinessPartners SET " +
                                            "IsSynced = @IsSynced, " +
                                            "ServerId = @ServerId " +
                                            "WHERE Identifier = @Identifier ";

                insertCommand.Parameters.AddWithValue("@IsSynced", isSynced);
                insertCommand.Parameters.AddWithValue("@ServerId", serverId);
                insertCommand.Parameters.AddWithValue("@Identifier", identifier);

                try
                {
                    insertCommand.ExecuteReader();
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage = error.Message;
                    response.Success        = false;
                    response.Message        = error.Message;
                    return(response);
                }
                db.Close();

                response.Success = true;
                return(response);
            }
        }
Пример #30
0
        private void btnCustomerAdd_Click(object sender, EventArgs e)
        {
            isReceiptFormEnable = false;
            if (!isBusinessPartnerAvailable)
            {
                if (txtName.Text.Trim().Length > 0 &&
                    txtAddress.Text.Trim().Length > 0 &&
                    cmbPhoneNumber.Text.Trim().Length >= 10 &&
                    cmbPhoneNumber.Text.Trim().Length <= 12)
                {
                    BusinessPartnerVM bspVM = new BusinessPartnerVM()
                    {
                        contacts  = new List <BusinessPartnerContactDetails>(),
                        addresses = new List <BusinessPartnerAddressDetails>()
                    };
                    BusinessPartnerContactDetails bspContactVM;
                    BusinessPartnerAddressDetails bspAddressVM = new BusinessPartnerAddressDetails();
                    bspContactVM = this.contacts.Where(selectContact => selectContact.PhoneNumber.Trim().ToUpper() == cmbPhoneNumber.Text.Trim().ToUpper()).FirstOrDefault();
                    if (bspContactVM != null)
                    {
                        bspVM.Id             = bspContactVM.BusinessPartnerId;
                        bspVM.mpt_StatusEnum = (int)BusinessPartnerStatusEnum.Active;
                        bspAddressVM.Id      = this.selectedBSP.addresses.FirstOrDefault().Id;
                    }
                    else
                    {
                        bspContactVM             = new BusinessPartnerContactDetails();
                        bspAddressVM             = new BusinessPartnerAddressDetails();
                        bspContactVM.Id          = 0;
                        bspContactVM.PhoneNumber = cmbPhoneNumber.Text;
                        bspContactVM.Email       = "";
                        bspAddressVM.Id          = 0;
                    }
                    bspVM.Name           = txtName.Text;
                    bspAddressVM.Address = txtAddress.Text;

                    bspVM.contacts  = bspVM.contacts.Append(bspContactVM);
                    bspVM.addresses = bspVM.addresses.Append(bspAddressVM);

                    using (ReceiptBLL receipt = new ReceiptBLL())
                    {
                        BusinessPartnerResponse bspResponse = receipt.ManageBusinessPartner(bspVM);
                        bspVM.Id = bspResponse.BusinessPartnerId;

                        bspContactVM = (from contact in bspVM.contacts
                                        select contact).FirstOrDefault();

                        bspAddressVM = (from address in bspVM.addresses
                                        select address).FirstOrDefault();
                        bspContactVM.BusinessPartnerId = bspResponse.BusinessPartnerId;
                        bspContactVM.Id = bspResponse.ContactId;
                        bspAddressVM.BusinessPartnerId = bspResponse.BusinessPartnerId;
                        bspAddressVM.Id = bspResponse.AddressId;

                        this.selectedBSP = bspVM;
                        this.setBspLables(this.selectedBSP);
                        this.btnCustomerAdd.Enabled   = false;
                        this.btnCustomerReset.Enabled = false;
                    }
                }
                else
                {
                    MessageBox.Show("Mandatory fields are missing");
                }
            }
            else
            {
                this.setBspLables(this.selectedBSP);
            }
        }