public static DocumentSync AddOrUpdateBusinessPartner(BusinessPartner BusinessPartner)
        {
            DocumentSync rt = new DocumentSync();

            SAPbobsCOM.BusinessPartners oBP = SAP.SAPCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners);
            oBP.CardCode = BusinessPartner.CardCode;
            oBP.CardName = BusinessPartner.CardName;
            int rtCode = 1;

            if (oBP.GetByKey(BusinessPartner.CardCode))
            {
                rtCode = oBP.Update();
            }
            else
            {
                rtCode = oBP.Add();
            }
            if (rtCode != 0)
            {
                rt.SyncResult = "N";
                rt.SyncMsg    = SAP.SAPCompany.GetLastErrorDescription();
            }
            else
            {
                rt.SyncResult = "Y";
                rt.SyncMsg    = "sync successful";
            }
            return(rt);
        }
        public int CreateBusinessPartner(BusinessPartnerDto dto, int customerId)
        {
            BusinessPartner partner = new BusinessPartner();

            UpdatePartner(dto, ref partner);

            var customer = _repository.Load <Customer>(customerId);

            using (TransactionScope scope = new TransactionScope())
            {
                int returnVal = -1;
                try
                {
                    customer.Partners.Add(partner);
                    _repository.Save <BusinessPartner>(partner);
                    _repository.Update <Customer>(customer);
                    returnVal = partner.Id;
                    scope.Complete();
                }
                catch (Exception ex)
                {
                    _log.Error("Error during creatin new Business Partner", ex);
                }
                return(returnVal);
            }
        }
Example #3
0
        public void AddingCustomerWithCidShouldFailAndThrowException()
        {
            //Given a BusinessPartner repository
            var numberOfCustomerBefore = DalService.CreateUnitOfWork().BusinessPartners.CountAsync().Result;
            //When Adding a BusinessPartner with a Cid (not null)
            var businessPartner = new BusinessPartner
            {
                Key  = "000",
                Name = "testName"
            };
            //Than the adding function will throw an exception
            BusinessPartner addedBusinessPartner = null;
            Action          comparison           = () =>
            {
                using var uow        = DalService.CreateUnitOfWork();
                addedBusinessPartner = uow.BusinessPartners.AddAsync(businessPartner).Result;
                uow.CompleteAsync().Wait();
            };

            comparison.Should().Throw <Exception>();

            //and the database will not affected
            DalService.CreateUnitOfWork().BusinessPartners.CountAsync().Result.Should().Be(numberOfCustomerBefore);

            //and the returned BusinessPartner need to be null
            (addedBusinessPartner == null).Should().BeTrue();
        }
Example #4
0
        private void FormatMultiplos()
        {
            var bp    = new BusinessPartner(Program.GetCurrentCompanyDb());
            var query = new TableQuery(bp);

            var choose = new ChooseFromListHelper(
                cardCodeMultEdit, cardNameMultEdit,
                query,
                BusinessPartner.FieldsName.CardCode,
                BusinessPartner.FieldsName.CardName,
                "Parceiros");

            choose.AllowSelectionsMultiples = true;

            choose.AfterTryGetRecord += (o, args) =>
            {
                gridView1.Columns.Clear();
                var selecionados = args.Records.Select(c =>
                {
                    var newBp = B1Helper.GetByKey <BusinessPartner>(Program.GetCurrentCompanyDb(), c["CardCode"]);
                    return(newBp);
                })
                                   .ToList();

                dataGrid1.DataSource = selecionados;
            };
        }
        public void AddCustomerWithoutNameShouldThrowValidateException()
        {
            //Given a BusinessPartner with empty or
            var customerToAdd = new BusinessPartner()
            {
                Name = null
            };
            var customerToAdd2 = new BusinessPartner()
            {
                Name = "  "
            };

            //When try to add the BusinessPartner
            var aggregateException  = _customerService.AddBusinessPartnerAsync(customerToAdd, CancellationToken.None).Exception;
            var aggregateException2 = _customerService.AddBusinessPartnerAsync(customerToAdd2, CancellationToken.None).Exception;

            //Then the operation should throw a ValidationException
            aggregateException.Should().NotBeNull();
            aggregateException2.Should().NotBeNull();

            var error = aggregateException.InnerException;

            error.Should().BeOfType(typeof(ValidationException));
            error = aggregateException2.InnerException;
            error.Should().BeOfType(typeof(ValidationException));
        }
Example #6
0
        public async Task <BusinessPartner> AddBusinessPartnerAsync(BusinessPartner businessPartner,
                                                                    CancellationToken cancellation)
        {
            var validator = new CustomerValidator(ValidateCardGroupExist, ValidateSalesmanCodeExist);

            validator.RuleFor(x => x.Name).NotEmpty();
            validator.RuleFor(x => x.GroupSn).Must(ValidateCardGroupExist)
            .WithMessage(x => $"Card Group {x.GroupSn} is invalid");
            validator.RuleFor(x => x.SalesmanCode).Must(ValidateSalesmanCodeExist)
            .WithMessage(x => $"Salesman with code {x.SalesmanCode} is  invalid");
            validator.RuleFor(x => x.Key).Null();
            validator.RuleFor(x => x.CreationDateTime).Null();
            var isBusinessPannerValid = await validator.ValidateAsync(businessPartner, cancellation);

            if (!isBusinessPannerValid.IsValid)
            {
                throw new InvalidStateException(isBusinessPannerValid.Errors
                                                .Select(x => x.ErrorMessage).Aggregate((s1, s2) => $"{s1},{s2}"));
            }


            using var transaction            = _dalService.CreateUnitOfWork();
            businessPartner.CreationDateTime = DateTime.Now;
            var result = await transaction.BusinessPartners.AddAsync(businessPartner);

            await transaction.CompleteAsync(cancellation);

            return(result);
        }
        public async Task <ActionResult <BusinessPartner> > PostBusinessPartner(BusinessPartner businessPartner)
        {
            _context.Business_Partners.Add(businessPartner);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetBusinessPartner", new { id = businessPartner.Id }, businessPartner));
        }
        public ActionResult Add(BusinessPartnerBindingModel model)
        {
            //check if model is valid, if not retrn to Index and dispay error message
            if (!this.ModelState.IsValid)
            {
                TempData["class"]        = "alert-danger";
                TempData["Response-bad"] = "Unable to add new Business Partner ";
                return(RedirectToAction("Index"));
            }

            //check if entity with current name exists
            if (_bussinessPartner.All().Any(i => i.Name == model.Name))
            {
                TempData["class"]    = "alert-danger";
                TempData["Response"] = "Bad Request! Unvalid Business Partner should be unique!";
                return(RedirectToAction("Index"));
            }
            //project to db model and create it
            var partner = new BusinessPartner()
            {
                Email       = model.Email,
                Name        = model.Name,
                PhoneNumber = model.PhoneNumber,
            };

            _bussinessPartner.Add(partner);

            return(RedirectToRoute("BusinessPartner"));
        }
Example #9
0
        /// <summary>
        ///  Create detail web api model from domain model
        /// </summary>
        public static Models.BusinessPartnerDetail CreateFromForRa(this BusinessPartner source)
        {
            if (source == null)
            {
                return(null);
            }

            return(new Models.BusinessPartnerDetail
            {
                BusinessPartnerId = source.BusinessPartnerId,
                BusinessPartnerName = source.BusinessPartnerName,
                BusinessPartnerDesciption = source.BusinessPartnerDesciption,
                IsIndividual = source.IsIndividual,
                BusinessLegalStatusId = source.BusinessLegalStatusId,
                PaymentTermId = source.PaymentTermId,
                BPRatingTypeId = source.BPRatingTypeId,
                BusinessPartnerCode = source.BusinessPartnerCode,
                BusinessPartnerEmailAddress = source.BusinessPartnerEmailAddress,
                BusinessPartnerIsValid = source.BusinessPartnerIsValid,
                CompanyId = source.CompanyId,
                DealingEmployeeId = source.DealingEmployeeId,
                IsSystemGuarantor = source.IsSystemGuarantor,
                NonSystemGuarantor = source.NonSystemGuarantor,
                SystemGuarantorId = source.SystemGuarantorId,
                BusinessPartnerIndividual = source.BusinessPartnerIndividual != null?source.BusinessPartnerIndividual.CreateFrom() : new ApiModel.BusinessPartnerIndividual(),
                                                BusinessPartnerCompany = source.BusinessPartnerCompany != null?source.BusinessPartnerCompany.CreateFrom() : new ApiModel.BusinessPartnerCompany(),
                                                                             BusinessPartnerPhoneNumbers = source.BusinessPartnerPhoneNumbers != null?source.BusinessPartnerPhoneNumbers.Select(x => x.CreateFrom()).ToList() : new List <ApiModel.Phone>(),
                                                                                                               BusinessPartnerAddressList = source.BusinessPartnerAddressList != null?source.BusinessPartnerAddressList.Select(x => x.CreateFrom()).ToList() : new List <ApiModel.Address>(),
                                                                                                                                                PaymentTerm = source.PaymentTerm != null?source.PaymentTerm.CreateFrom() : null
            });
        }
        public static BusinessPartnerViewModel ConvertToBusinessPartnerViewModel(this BusinessPartner businessPartner)
        {
            BusinessPartnerViewModel businessPartnerViewModel = new BusinessPartnerViewModel()
            {
                Id         = businessPartner.Id,
                Identifier = businessPartner.Identifier,

                Code         = businessPartner.Code,
                InternalCode = businessPartner.InternalCode,
                Name         = businessPartner.Name,

                PIB = businessPartner.PIB,
                PIO = businessPartner.PIO,
                IdentificationNumber = businessPartner.IdentificationNumber,
                Address = businessPartner.Address,
                DueDate = businessPartner.DueDate,

                WebSite       = businessPartner.WebSite,
                ContactPerson = businessPartner.ContactPerson,

                IsInPDV = businessPartner.IsInPDV,

                JBKJS = businessPartner.JBKJS,

                NameGer           = businessPartner.NameGer,
                IsInPDVGer        = businessPartner.IsInPDVGer,
                TaxAdministration = businessPartner.TaxAdministration?.ConvertToTaxAdministrationViewModelLite(),
                IBAN           = businessPartner.IBAN,
                BetriebsNumber = businessPartner.BetriebsNumber,
                Customer       = businessPartner.Customer,
                Country        = businessPartner.Country?.ConvertToCountryViewModelLite(),
                CountrySrb     = businessPartner.CountrySrb?.ConvertToCountryViewModelLite(),
                CitySrb        = businessPartner.CitySrb?.ConvertToCityViewModelLite(),
                City           = businessPartner.City?.ConvertToCityViewModelLite(),

                AddressGer       = businessPartner.AddressGer,
                Sector           = businessPartner.Sector?.ConvertToSectorViewModelLite(),
                Agency           = businessPartner.Agency?.ConvertToAgencyViewModelLite(),
                Vat              = businessPartner.Vat?.ConvertToVatViewModelLite(),
                Discount         = businessPartner.Discount?.ConvertToDiscountViewModelLite(),
                TaxNr            = businessPartner.TaxNr,
                CommercialNr     = businessPartner.CommercialNr,
                ContactPersonGer = businessPartner.ContactPersonGer,

                VatDeductionFrom = businessPartner.VatDeductionFrom,
                VatDeductionTo   = businessPartner.VatDeductionTo,

                PdvType  = businessPartner.PdvType,
                Path     = businessPartner.Path,
                IsActive = businessPartner.Active,

                CreatedBy = businessPartner.CreatedBy?.ConvertToUserViewModelLite(),
                Company   = businessPartner.Company?.ConvertToCompanyViewModelLite(),

                UpdatedAt = businessPartner.UpdatedAt,
                CreatedAt = businessPartner.CreatedAt,
            };

            return(businessPartnerViewModel);
        }
        public async Task <IActionResult> Edit(int id, [Bind("BusinessPartnerId,Name,Debitor,Kreditor")] BusinessPartner businessPartner)
        {
            if (id != businessPartner.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(businessPartner);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BusinessPartnerExists(businessPartner.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(businessPartner));
        }
Example #12
0
        public BusinessPartnerEditor(BusinessPartner bp, ListController bpc)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            this.bp  = bp;
            this.bpc = bpc;
            stateBox.Items.Add(StateType.IN.ToString());
            stateBox.Items.Add(StateType.OH.ToString());
            stateBox.Items.Add(StateType.TX.ToString());

            nameLabel.Text = bp.name;
            if (bp.address != null)
            {
                cityBox.Text = bp.address.city;
                if (bp.address.phoneNumber != null)
                {
                    textBox1.Text = bp.address.phoneNumber.number;
                }
                stateBox.Text = bp.address.state.ToString();
            }

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }
Example #13
0
 /// <summary>
 /// Delete / Remove an Business Partner by given the whole object
 /// </summary>
 /// <param name="entity"></param>
 public void Remove(BusinessPartner entity)
 {
     var partner = _partnerRepository.Find(entity.Id);
     CheckIfAnyPartnerIsRelatedWithEmployee(entity);
     _partnerRepository.Remove(partner);
     _partnerRepository.SaveChanges();
 }
        public void ProcessarNovosClientes(List <Cliente> clientes)
        {
            try
            {
                BusinessPartnersDAL bpDAL = new BusinessPartnersDAL(CommonConn.oCompany);
                string errorMessage       = "";

                if (clientes.Count > 0)
                {
                    foreach (Cliente cl in clientes)
                    {
                        BusinessPartner businessPartners = new BusinessPartner();

                        businessPartners.CardCode = cl.id;

                        bpDAL.InserirBusinessPartner(businessPartners, out errorMessage);
                    }
                }
            }
            catch (Exception e)
            {
                Log.WriteLog("ProcessarNovosClientes Exception:" + e.Message);
                throw;
            }
        }
Example #15
0
        public async Task <IActionResult> Put(BusinessPartner businessPartner)
        {
            _context.Entry(businessPartner).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(NoContent());
        }
        public void UpdateCompany(BusinessPartner businessPartner)
        {
            var query      = BusinessPartnerQueries.Update;
            var parameters = DataHelper.ExtractParameters(businessPartner);

            dbContext.ExecuteNonQuery(query, parameters);
        }
Example #17
0
        public static BusinessPartner ConvertToBusinessPartner(this BusinessPartnerViewModel businessPartnerViewModel)
        {
            BusinessPartner businessPartner = new BusinessPartner()
            {
                Id         = businessPartnerViewModel.Id,
                Identifier = businessPartnerViewModel.Identifier,

                Code = businessPartnerViewModel.Code,
                Name = businessPartnerViewModel.Name,

                Director = businessPartnerViewModel.Director,

                Address    = businessPartnerViewModel.Address,
                InoAddress = businessPartnerViewModel.InoAddress,

                PIB     = businessPartnerViewModel.PIB,
                MatCode = businessPartnerViewModel.MatCode,

                Mobile = businessPartnerViewModel.Mobile,
                Phone  = businessPartnerViewModel.Phone,
                Email  = businessPartnerViewModel.Email,

                ActivityCode = businessPartnerViewModel.ActivityCode,

                BankAccountNumber = businessPartnerViewModel.BankAccountNumber,

                OpeningDate       = businessPartnerViewModel.OpeningDate,
                BranchOpeningDate = businessPartnerViewModel.BranchOpeningDate,

                CreatedById = businessPartnerViewModel.CreatedBy?.Id ?? null,
                CreatedAt   = businessPartnerViewModel.CreatedAt
            };

            return(businessPartner);
        }
        public void InserirBusinessPartner(BusinessPartner businessPartner, out string messageError)
        {
            int addBPNumber = 0;

            try
            {
                SAPbobsCOM.BusinessPartners oBusinessPartner = (SAPbobsCOM.BusinessPartners)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners);

                oBusinessPartner.CardCode = businessPartner.CardCode;

                addBPNumber = oBusinessPartner.Add();
            }
            catch (Exception e)
            {
                Log.WriteLog("InserirBusinessPartner Exception: " + e.Message);
                throw;
            }

            if (addBPNumber != 0)
            {
                messageError = oCompany.GetLastErrorDescription();
                Log.WriteLog("InserirBusinessPartner error SAP: " + messageError);
            }
            else
            {
                string CardCode = oCompany.GetNewObjectKey();
                messageError = "";
                Log.WriteLog("BusinessPartner " + CardCode + " inserido com sucesso.");
            }
        }
 public void UpdatePartner(BusinessPartnerDto dto, ref BusinessPartner poco)
 {
     poco.Description = dto.Description;
     poco.Iban        = dto.Iban;
     poco.Id          = dto.Id;
     poco.Name        = dto.Title;
 }
Example #20
0
        public async Task <IActionResult> PutBusinessPartner(Guid id, BusinessPartner businessPartner)
        {
            if (id != businessPartner.BusinessPartnerId)
            {
                return(BadRequest());
            }

            _context.Entry(businessPartner).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BusinessPartnerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public int Add(BusinessPartner newPartner)
        {
            var query      = BusinessPartnerQueries.Insert;
            var parameters = DataHelper.ExtractParameters(newPartner);

            return(dbContext.Execute <int>(query, parameters));
        }
Example #22
0
        public IActionResult UpdateBP([FromBody] BusinessPartner model)
        {
            var msg  = new Message <BusinessPartner>();
            var data = DbClientFactory <BPDbClient> .Instance.UpdateBP(model, appSettings.Value.DbConn);

            if (data == "C200")
            {
                msg.IsSuccess = true;
                if (model.Personid == 0)
                {
                    msg.ReturnMessage = "User saved successfully";
                }
                else
                {
                    msg.ReturnMessage = "User updated successfully";
                }
            }
            else if (data == "C201")
            {
                msg.IsSuccess     = false;
                msg.ReturnMessage = "Email Id already exists";
            }
            else if (data == "C202")
            {
                msg.IsSuccess     = false;
                msg.ReturnMessage = "Mobile Number already exists";
                //    }
                return(Ok(msg));
            }
            return(Ok(msg));
        }
Example #23
0
 /// <summary>
 ///  Create detail web api model from domain model
 /// </summary>
 public static Models.BusinessPartnerDetail CreateApiDetailFromDomainModel(this BusinessPartner source)
 {
     return(new Models.BusinessPartnerDetail
     {
         BusinessPartnerId = source.BusinessPartnerId,
         BusinessPartnerName = source.BusinessPartnerName,
         BusinessPartnerDesciption = source.BusinessPartnerDesciption,
         IsIndividual = source.IsIndividual,
         BusinessLegalStatusId = source.BusinessLegalStatusId,
         PaymentTermId = source.PaymentTermId,
         BPRatingTypeId = source.BPRatingTypeId,
         BusinessPartnerCode = source.BusinessPartnerCode,
         BusinessPartnerEmailAddress = source.BusinessPartnerEmailAddress,
         BusinessPartnerIsValid = source.BusinessPartnerIsValid,
         CompanyId = source.CompanyId,
         DealingEmployeeId = source.DealingEmployeeId,
         IsSystemGuarantor = source.IsSystemGuarantor,
         NonSystemGuarantor = source.NonSystemGuarantor,
         SystemGuarantorId = source.SystemGuarantorId,
         BusinessPartnerIndividual = source.BusinessPartnerIndividual.CreateFrom(),
         BusinessPartnerCompany = source.BusinessPartnerCompany.CreateFrom(),
         BusinessPartnerInTypes = source.BusinessPartnerInTypes.Select(x => x.CreateFrom()).ToList(),
         BusinessPartnerPhoneNumbers = source.BusinessPartnerPhoneNumbers.Select(x => x.CreateFrom()).ToList(),
         BusinessPartnerAddressList = source.BusinessPartnerAddressList.Select(x => x.CreateFrom()).ToList(),
         BusinessPartnerMarketingChannels = source.BusinessPartnerMarketingChannels.Select(x => x.CreateFrom()).ToList(),
         BusinessPartnerRelationshipItemList = source.BusinessPartnerRelationshipItemList.Select(x => x.CreateFrom()).ToList()
     });
 }
Example #24
0
        public static BusinessPartnerViewModel ConvertToBusinessPartnerViewModelLite(this BusinessPartner businessPartner)
        {
            BusinessPartnerViewModel businessPartnerViewModel = new BusinessPartnerViewModel()
            {
                Id         = businessPartner.Id,
                Identifier = businessPartner.Identifier,

                Code = businessPartner.Code,
                Name = businessPartner.Name,

                Director = businessPartner.Director,

                Address    = businessPartner.Address,
                InoAddress = businessPartner.InoAddress,

                PIB     = businessPartner.PIB,
                MatCode = businessPartner.MatCode,

                Mobile = businessPartner.Mobile,
                Phone  = businessPartner.Phone,
                Email  = businessPartner.Email,

                ActivityCode = businessPartner.ActivityCode,

                BankAccountNumber = businessPartner.BankAccountNumber,

                OpeningDate       = businessPartner.OpeningDate,
                BranchOpeningDate = businessPartner.BranchOpeningDate,

                UpdatedAt = businessPartner.UpdatedAt,
                CreatedAt = businessPartner.CreatedAt
            };

            return(businessPartnerViewModel);
        }
Example #25
0
        public string UpdateBP(BusinessPartner model, string connString)
        {
            var outParam = new SqlParameter("@ReturnCode", SqlDbType.NVarChar, 20)
            {
                Direction = ParameterDirection.Output
            };

            SqlParameter[] param =
            {
                new SqlParameter("@Id",          model.Personid),
                new SqlParameter("@LastName",    model.LastName),
                new SqlParameter("@FirstName",   model.FirstName),
                new SqlParameter("@ForeignName", model.ForeignName),
                new SqlParameter("@DateOfBirth", model.DateOfBirth),
                new SqlParameter("@Gneder",      model.Gneder),
                new SqlParameter("@Email",       model.Email),
                new SqlParameter("@Website",     model.Website),
                new SqlParameter("@HomePhone",   model.HomePhone),
                new SqlParameter("@OfficePhone", model.OfficePhone),
                new SqlParameter("@Mobile",      model.Mobile),
                new SqlParameter("@Fax",         model.Fax),
                new SqlParameter("@Currency",    model.Currency),
                new SqlParameter("@Address1",    model.Address1),
                new SqlParameter("@Address2",    model.Address2),
                new SqlParameter("@City",        model.City),
                new SqlParameter("@State",       model.State),
                new SqlParameter("@Zip",         model.Zip),
                new SqlParameter("@Country",     model.Country),
                new SqlParameter("@IsActive",    model.IsActive)
            };
            SqlHelper.ExecuteProcedureReturnString(connString, "procUpdateBP", param);
            return((string)outParam.Value);
        }
Example #26
0
        private void button5_Click(object sender, EventArgs e)
        {
            BusinessPartner bp    = new BusinessPartner(Program.GetCurrentCompanyDb());
            TableQuery      query = new TableQuery(bp);

            var script = new CommandService().SqlQuery(query, 1, 20, "CardCode", eOrder.eoASC);
        }
Example #27
0
        public async Task <BusinessPartner> UpdateBusinessPartnerAsync(string cid, BusinessPartner businessPartner,
                                                                       CancellationToken cancellation)
        {
            var validator = new CustomerValidator(ValidateCardGroupExist, ValidateSalesmanCodeExist);

            validator.RuleFor(x => x.Key).Must(x => x == cid);
            validator.RuleFor(x => x.Name).Must(x => x == null || !string.IsNullOrWhiteSpace(x));
            validator.RuleFor(x => x.GroupSn).Must(x => !x.HasValue || ValidateCardGroupExist(x))
            .WithMessage(x => $"Card Group {x.GroupSn} is invalid");
            validator.RuleFor(x => x.SalesmanCode).Must(x => !x.HasValue || ValidateSalesmanCodeExist(x))
            .WithMessage(x => $"Salesman with code {x.SalesmanCode} is  invalid");
            var isBusinessPannerValid = await validator.ValidateAsync(businessPartner, cancellation);

            if (!isBusinessPannerValid.IsValid)
            {
                throw new InvalidStateException(isBusinessPannerValid.Errors
                                                .Select(x => x.ErrorMessage).Aggregate((s1, s2) => $"{s1},{s2}"));
            }

            using var transaction = _dalService.CreateUnitOfWork();
            //TODO check which field are updateable
            var result = await transaction.BusinessPartners.UpdateAsync(businessPartner);

            await transaction.CompleteAsync(cancellation);

            return(result);
        }
        public ActionResult Edit(BusinessPartnerBindingModel model)
        {
            //check if model state is valid, if not redirect to Edit/{id} + returns a message
            if (!this.ModelState.IsValid)
            {
                TempData["Response"] = "Unable to Save Changes. Try again !";
                TempData["class"]    = "alert-danger";
                return(RedirectToAction("Edit", new { id = model.Id }));
            }

            //check if an entity with a inputed name is existing
            if (_bussinessPartner.All().Any(i => i.Name == model.Name))
            {
                TempData["class"]    = "alert-danger";
                TempData["Response"] = "Bad Request! Unvalid Input Username should be unique!";
                return(RedirectToAction("Index"));
            }

            // project a new entity with given information
            var partner = new BusinessPartner()
            {
                Email       = model.Email,
                Name        = model.Name,
                PhoneNumber = model.PhoneNumber,
                Id          = model.Id
            };

            //update that entity in DB
            _bussinessPartner.Update(partner);
            TempData["class"]    = "alert-success";
            TempData["Response"] = "Successfully updated that entity!";

            return(RedirectToAction("Edit", new { id = model.Id }));
        }
Example #29
0
        public FormGridDemo()
        {
            InitializeComponent();

            Permission.HasPermission(Security.PackinlistRemove, PermissionType.Full);

            gridView1.FormatGrid <BusinessPartner>(
                Program.GetCurrentCompanyDb());

            var bp    = new BusinessPartner(Program.GetCurrentCompanyDb());
            var query = new TableQuery(bp);

            gridView1.Columns[BusinessPartner.FieldsName.CardCode].SetLinkedButton(BoLinkedObject.lf_BusinessPartner);

            var choose = new ChooseFromListHelper(
                gridView1.Columns[BusinessPartner.FieldsName.CardCode],
                gridView1.Columns[BusinessPartner.FieldsName.CardName],
                query,
                BusinessPartner.FieldsName.CardCode,
                BusinessPartner.FieldsName.CardName, "Clientes");

            choose.AfterTryGetRecord += delegate(object sender, ChooseFromListEventArgs e)
            {
                var rowSel = gridView1.GetFocusedDataRow();
                rowSel.SetField <string>(
                    BusinessPartner.FieldsName.CardCode,
                    e.Record.Field <String>(BusinessPartner.FieldsName.CardCode));
                rowSel.SetField <string>(
                    BusinessPartner.FieldsName.CardName,
                    e.Record.Field <String>(BusinessPartner.FieldsName.CardName));
            };

            var chooseNotaFiscalCstCode = new ChooseFromListHelper(editText2,
                                                                   editTextButton1,
                                                                   new TableQuery(new NotaFiscalCstCode(Program.GetCurrentCompanyDb())), eCondition.ecLike,
                                                                   NotaFiscalCstCode.FieldsName.Code, NotaFiscalCstCode.FieldsName.Situation,
                                                                   "Imposto Cst"
                                                                   );

            new ChooseFromListHelper(editTextChartOfAcc, editTextButtonChartOfAcc, new TableQuery(
                                         new ChartOfAccount(
                                             Program.GetCurrentCompanyDb())),
                                     ChartOfAccount.FieldsName.AcctCode,
                                     ChartOfAccount.FieldsName.AcctName, "Contas contábeis");

            dataGrid1.DataSource = bp.GetData();

            gridView1.SetAllEditable(true);

            gridView1.Columns[BusinessPartner.FieldsName.CardCode].OptionsColumn.AllowEdit = true;
            gridView1.Columns[BusinessPartner.FieldsName.CardName].OptionsColumn.AllowEdit = true;

            //gridView1.Columns[BusinessPartner.FieldsName.CardCode].ColumnEdit.ReadOnly = false;
            //gridView1.Columns[BusinessPartner.FieldsName.CardName].ColumnEdit.ReadOnly = false;

            editText1.Select();

            this.Load += new EventHandler(Form2_Load);
        }
Example #30
0
        public async Task <IActionResult> Post(BusinessPartner businessPartner)
        {
            businessPartner.DeliveryRoute = _context.DeliveryRoutes.FirstOrDefault(dr => dr.Id == businessPartner.DeliveryRouteId);
            _context.Add(businessPartner);
            await _context.SaveChangesAsync();

            return(Ok(businessPartner.Id));
        }
        public ActionResult addContact(string id, ContactEmployee contact)
        {
            #region User identification
            IIdentity context = HttpContext.User.Identity;
            bool admin = false;
            bool customerCreator = false;
            bool purchaseOrderCreator = false;
            int companyId = 0;
            string userName = "";
            AppConnData appConnData = new AppConnData();

            if (context.IsAuthenticated)
            {

                System.Web.Security.FormsIdentity ci = (System.Web.Security.FormsIdentity)HttpContext.User.Identity;
                string[] userRole = ci.Ticket.UserData.Split('|');

                admin = int.Parse(userRole[1]) == 1 ? true : false;
                customerCreator = int.Parse(userRole[2]) == 1 ? true : false;
                purchaseOrderCreator = int.Parse(userRole[3]) == 1 ? true : false;
                companyId = int.Parse(userRole[4]);
                userName = ci.Name;
                appConnData = GetAppConnData(companyId);
            }
            #endregion
            string[] customerData = HexSerialization.HexToString(id).Split('|');

            BusinessPartner customer = new BusinessPartner() { cardCode = customerData[0] };

            try
            {
                contact.cardCode = customerData[0];
                backEnd.AddBusinessPartnerContact(contact, appConnData);
            }
            catch (FaultException<DataAccessFault> ex)
            {
                ViewBag.mensaje = string.Format("Codigo {0} error:{1} {2}", ex.Code, ex.Detail.Description, ex.Message);
                return View(contact);
            }

            return RedirectToAction("addContact", new { id = id });
        }
 public void MemorizeInnerReferences(IList<DocumentLineItemEntity> refs, string controlNumber, BusinessPartner partner)
 {
     _docParser.MemorizeInnerReferences(refs, controlNumber, partner);
 }
 public static BusinessPartner CreateBusinessPartner(string businessPartnerID)
 {
     BusinessPartner businessPartner = new BusinessPartner();
     businessPartner.BusinessPartnerID = businessPartnerID;
     return businessPartner;
 }
 public IEnumerable<Segment> MemorizeOuterReferences(List<Segment> segList, string controlNumber, BusinessPartner partner)
 {
     return  _docParser.MemorizeOuterReferences(segList, controlNumber, partner);
 }
 public void AddToBusinessPartnerCollection(BusinessPartner businessPartner)
 {
     base.AddObject("BusinessPartnerCollection", businessPartner);
 }
 public static IDocumentParser ParserFor(this DocContainer doc, BusinessPartner partner)
 {
     var parsers = ServiceLocator.Current.GetAllInstances(typeof(IDocumentParser)).Select(p => (IDocumentParser)p);
     return parsers.Find(p => p.CanProcess(partner,doc.DocType));
 }
 public bool CanParseFor(BusinessPartner partner)
 {
     return true;
 }
 public static IFileParser GetFileParserFor(this IWindsorContainer container, BusinessPartner partner)
 {
     return container.Resolve<IFileParser>(partner.Code + "FileParser");
 }
 public EDITransmissionPackage(EDIXmlInterchangeControl ic, BusinessPartner bp)
 {
     _ic = ic;
     _bp = bp;
 }
            public ActionResult edit(string id, CustomerViewModel customer)
            {
            try
            {
                #region User identification
                IIdentity context = HttpContext.User.Identity;
                bool admin = false;
                bool customerCreator = false;
                bool purchaseOrderCreator = false;
                int companyId = 0;
                string userName = "";
                AppConnData appConnData = new AppConnData();

                if (context.IsAuthenticated)
                {

                    System.Web.Security.FormsIdentity ci = (System.Web.Security.FormsIdentity)HttpContext.User.Identity;
                    string[] userRole = ci.Ticket.UserData.Split('|');

                    admin = int.Parse(userRole[1]) == 1 ? true : false;
                    customerCreator = int.Parse(userRole[2]) == 1 ? true : false;
                    purchaseOrderCreator = int.Parse(userRole[3]) == 1 ? true : false;
                    companyId = int.Parse(userRole[4]);
                    userName = ci.Name;
                    appConnData = GetAppConnData(companyId);
                }
                #endregion

                BusinessPartner bp = new BusinessPartner()
                {
                    #region data
                    cardType = customer.bpType == "C" ? CardType.Customer : CardType.Lead,
                    cardCode = customer.cardCode,
                    cardName = customer.cardName,
                    cardFName = customer.cardFName,
                    groupCode = customer.groupCode,
                    licTradNum = customer.licTradNum,
                    currency = customer.currency,
                    password = customer.password,
                    e_Mail = customer.e_Mail,
                    phone1 = customer.phone1,
                    phone2 = customer.phone2,
                    slpCode = customer.slpCode,
                    dunTerm = customer.dunTerm,
                    groupNum = customer.groupNum,
                    qryGroup1 = customer.qryGroup1,
                    qryGroup2 = customer.qryGroup2,
                    qryGroup3 = customer.qryGroup3,
                    qryGroup4 = customer.qryGroup4,
                    qryGroup5 = customer.qryGroup5,
                    qryGroup6 = customer.qryGroup6,
                    qryGroup7 = customer.qryGroup7,
                    qryGroup8 = customer.qryGroup8,
                    qryGroup9 = customer.qryGroup9,
                    qryGroup10 = customer.qryGroup10,
                    qryGroup11 = customer.qryGroup11,
                    qryGroup12 = customer.qryGroup12,
                    qryGroup13 = customer.qryGroup13,
                    qryGroup14 = customer.qryGroup14,
                    qryGroup15 = customer.qryGroup15,
                    qryGroup16 = customer.qryGroup16,
                    qryGroup17 = customer.qryGroup17,
                    qryGroup18 = customer.qryGroup18,
                    qryGroup19 = customer.qryGroup19,
                    qryGroup20 = customer.qryGroup20,
                    qryGroup21 = customer.qryGroup21,
                    qryGroup22 = customer.qryGroup22,
                    qryGroup23 = customer.qryGroup23,
                    qryGroup24 = customer.qryGroup24,
                    qryGroup25 = customer.qryGroup25,
                    qryGroup26 = customer.qryGroup26,
                    qryGroup27 = customer.qryGroup27,
                    qryGroup28 = customer.qryGroup28,
                    qryGroup29 = customer.qryGroup29,
                    qryGroup30 = customer.qryGroup30,
                    qryGroup31 = customer.qryGroup31,
                    qryGroup32 = customer.qryGroup32,
                    qryGroup33 = customer.qryGroup33,
                    qryGroup34 = customer.qryGroup34,
                    qryGroup35 = customer.qryGroup35,
                    qryGroup36 = customer.qryGroup36,
                    qryGroup37 = customer.qryGroup37,
                    qryGroup38 = customer.qryGroup38,
                    qryGroup39 = customer.qryGroup39,
                    qryGroup40 = customer.qryGroup40,
                    qryGroup41 = customer.qryGroup41,
                    qryGroup42 = customer.qryGroup42,
                    qryGroup43 = customer.qryGroup43,
                    qryGroup44 = customer.qryGroup44,
                    qryGroup45 = customer.qryGroup45,
                    qryGroup46 = customer.qryGroup46,
                    qryGroup47 = customer.qryGroup47,
                    qryGroup48 = customer.qryGroup48,
                    qryGroup49 = customer.qryGroup49,
                    qryGroup50 = customer.qryGroup50,
                    qryGroup51 = customer.qryGroup51,
                    qryGroup52 = customer.qryGroup52,
                    qryGroup53 = customer.qryGroup53,
                    qryGroup54 = customer.qryGroup54,
                    qryGroup55 = customer.qryGroup55,
                    qryGroup56 = customer.qryGroup56,
                    qryGroup57 = customer.qryGroup57,
                    qryGroup58 = customer.qryGroup58,
                    qryGroup59 = customer.qryGroup59,
                    qryGroup60 = customer.qryGroup60,
                    qryGroup61 = customer.qryGroup61,
                    qryGroup62 = customer.qryGroup62,
                    qryGroup63 = customer.qryGroup63,
                    qryGroup64 = customer.qryGroup64,
                    freeText = customer.freeText,
                    wtLiable = true,
                    userDefinedFields = new List<UserDefinedField>()
                    #endregion
                };

                #region UDF's
                bp.userDefinedFields.Add(new UserDefinedField()
                {
                    name = "U_BPCO_RTC",
                    value = customer.uBpcoRt,
                    type = UdfType.Alphanumeric
                });

                bp.userDefinedFields.Add(new UserDefinedField()
                {
                    name = "U_BPCO_TDC",
                    value = customer.uBpcoTdc,
                    type = UdfType.Alphanumeric
                });

                bp.userDefinedFields.Add(new UserDefinedField()
                {
                    name = "U_BPCO_CS",
                    value = customer.uBpcoCs,
                    type = UdfType.Alphanumeric
                });

                bp.userDefinedFields.Add(new UserDefinedField()
                {
                    name = "U_BPCO_City",
                    value = customer.uBpcoCity,
                    type = UdfType.Alphanumeric
                });

                bp.userDefinedFields.Add(new UserDefinedField()
                {
                    name = "U_BPCO_TP",
                    value = customer.uBpcoTp,
                    type = UdfType.Alphanumeric
                });

                bp.userDefinedFields.Add(new UserDefinedField()
                {
                    name = "U_CSS_IVA",
                    value = customer.uCssIva,
                    type = UdfType.Alphanumeric
                });

                bp.userDefinedFields.Add(new UserDefinedField()
                {
                    name = "U_CSS_aceptacion_fac",
                    value = customer.uCssAcceptInvoice,
                    type = UdfType.Integer
                });

                bp.userDefinedFields.Add(new UserDefinedField()
                {
                    name = "U_QCA_SEGMENTACION",
                    value = customer.uQcaSegment,
                    type = UdfType.Alphanumeric
                });
                #endregion

                backEnd.UpdateBusinessPartner(bp, appConnData);

            }
            catch (FaultException<DataAccessFault> ex)
            {
                ViewBag.mensaje = string.Format("Codigo {0} error:{1} {2}", ex.Code, ex.Detail.Description, ex.Message);
                return View(customer);
            }

            id = HexSerialization.StringToHex(string.Format("{0}|{1}", customer.cardCode, customer.cardName));
            return RedirectToAction("addContact", new { id = id });
            //customer.contactPersons = new List<ContactEmployee>();
            //return View("addContact", customer);
        }