Пример #1
0
        public async Task <IHttpActionResult> AddBusinessPartner(oBusinessPartner businessPartner)
        {
            try
            {
                if (!GlobalInstance.Instance.IsConnected)
                {
                    GlobalInstance.Instance.InitializeSboComObject();
                }
                var bp = await repo.GetByCardCode(businessPartner.CardCode);

                if (businessPartner != null)
                {
                    errMsg = string.Format("Business partner {0} already exist.", businessPartner.CardCode);
                    var resp = new HttpResponseMessage(HttpStatusCode.Conflict);
                    resp.Content      = new StringContent(errMsg);
                    resp.ReasonPhrase = "Object already exist.";
                    throw new HttpResponseException(resp);
                }

                if (repo.Add(businessPartner) < 0)
                {
                    errMsg = GlobalInstance.Instance.SBOErrorMessage;
                    var resp = new HttpResponseMessage(HttpStatusCode.Conflict);
                    resp.Content      = new StringContent(errMsg);
                    resp.ReasonPhrase = "SBO Error";
                    throw new HttpResponseException(resp);
                }

                return(Ok(string.Format("Business partner {0} succesfully added.", businessPartner.CardCode)));
            }
            catch (HttpResponseException ex)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
        }
Пример #2
0
        /// <summary>
        /// Add business partner
        /// </summary>
        /// <param name="businessPartner"></param>
        /// <returns></returns>
        public bool AddBusinessPartner(BusinessPartner businessPartner)
        {
            if (ValidateBusinessPartner(businessPartner))
            {
                //set master (business partner) properties
                #region Business Partner
                businessPartner.BusinessPartnerCode = "BP-Screen";
                businessPartner.UserDomainKey       = businessPartnerRepository.UserDomainKey;
                businessPartner.IsActive            = true;
                businessPartner.IsDeleted           = false;
                businessPartner.IsPrivate           = false;
                businessPartner.IsReadOnly          = false;
                businessPartner.RecCreatedDt        = DateTime.Now;
                businessPartner.RecLastUpdatedDt    = DateTime.Now;
                businessPartner.RecCreatedBy        = businessPartnerRepository.LoggedInUserIdentity;
                businessPartner.RecLastUpdatedBy    = businessPartnerRepository.LoggedInUserIdentity;
                businessPartner.RowVersion          = 0;
                #endregion

                //set child (business partner individual) properties
                #region Business Partner Individual

                businessPartner.BusinessPartnerIndividual.RecCreatedBy         =
                    businessPartner.BusinessPartnerIndividual.RecLastUpdatedBy =
                        businessPartnerRepository.LoggedInUserIdentity;
                businessPartner.BusinessPartnerIndividual.RecCreatedDt         =
                    businessPartner.BusinessPartnerIndividual.RecLastUpdatedDt =
                        DateTime.Now;
                businessPartner.BusinessPartnerIndividual.UserDomainKey = businessPartnerRepository.UserDomainKey;
                #endregion

                //set child (business partner company) properties
                #region Business Partner Company
                businessPartner.BusinessPartnerCompany.RecCreatedBy         =
                    businessPartner.BusinessPartnerCompany.RecLastUpdatedBy =
                        businessPartnerRepository.LoggedInUserIdentity;
                businessPartner.BusinessPartnerCompany.RecCreatedDt         =
                    businessPartner.BusinessPartnerCompany.RecLastUpdatedDt =
                        DateTime.Now;
                businessPartner.BusinessPartnerCompany.RecLastUpdatedBy =
                    businessPartner.BusinessPartnerCompany.RecCreatedBy =
                        "Cares";
                businessPartner.BusinessPartnerCompany.UserDomainKey = businessPartnerRepository.UserDomainKey;
                #endregion

                //set child (business partner intypes) properties
                #region Business Partner Intypes
                // set user domain key
                foreach (BusinessPartnerInType item in businessPartner.BusinessPartnerInTypes)
                {
                    item.UserDomainKey = businessPartnerRepository.UserDomainKey;
                }
                #endregion

                //set child (business partner phones) properties
                #region Business Partner Phones
                // set properties
                foreach (Phone item in businessPartner.BusinessPartnerPhoneNumbers)
                {
                    item.IsActive         = true;
                    item.IsDeleted        = false;
                    item.IsPrivate        = false;
                    item.IsReadOnly       = false;
                    item.RecCreatedDt     = DateTime.Now;
                    item.RecLastUpdatedDt = DateTime.Now;
                    item.RecCreatedBy     = businessPartnerRepository.LoggedInUserIdentity;
                    item.RecLastUpdatedBy = businessPartnerRepository.LoggedInUserIdentity;
                    item.RowVersion       = 0;
                    item.UserDomainKey    = businessPartnerRepository.UserDomainKey;
                }
                #endregion

                //set child (business partner address) properties
                #region Business Partner Address
                // set properties
                foreach (Address item in businessPartner.BusinessPartnerAddressList)
                {
                    item.IsActive         = true;
                    item.IsDeleted        = false;
                    item.IsPrivate        = false;
                    item.IsReadOnly       = false;
                    item.RecCreatedDt     = DateTime.Now;
                    item.RecLastUpdatedDt = DateTime.Now;
                    item.RecCreatedBy     = businessPartnerRepository.LoggedInUserIdentity;
                    item.RecLastUpdatedBy = businessPartnerRepository.LoggedInUserIdentity;
                    item.RowVersion       = 0;
                    item.UserDomainKey    = businessPartnerRepository.UserDomainKey;
                }
                #endregion

                //set child (business partner marketing channel) properties
                #region Business Partner Marketing Channel
                // set properties
                foreach (BusinessPartnerMarketingChannel item in businessPartner.BusinessPartnerMarketingChannels)
                {
                    item.RecCreatedDt     = DateTime.Now;
                    item.RecLastUpdatedDt = DateTime.Now;
                    item.RecCreatedBy     = businessPartnerRepository.LoggedInUserIdentity;
                    item.RecLastUpdatedBy = businessPartnerRepository.LoggedInUserIdentity;
                    item.RowVersion       = 0;
                    item.UserDomainKey    = businessPartnerRepository.UserDomainKey;
                }
                #endregion

                //set child (business partner relationship) properties
                #region Business Partner Relationship
                // set properties
                foreach (BusinessPartnerRelationship item in businessPartner.BusinessPartnerRelationshipItemList)
                {
                    item.RecCreatedDt     = DateTime.Now;
                    item.RecLastUpdatedDt = DateTime.Now;
                    item.RecCreatedBy     = businessPartnerRepository.LoggedInUserIdentity;
                    item.RecLastUpdatedBy = businessPartnerRepository.LoggedInUserIdentity;
                    item.RowVersion       = 0;
                    item.UserDomainKey    = businessPartnerRepository.UserDomainKey;
                }
                #endregion

                // save data
                businessPartnerRepository.Add(businessPartner);
                businessPartnerRepository.SaveChanges();
                return(true);
            }
            return(false);
        }
        public async Task <IHttpActionResult> AddBusinessPartner(oBusinessPartner businessPartner)
        {
            try
            {
                if (!GlobalInstance.Instance.IsConnected)
                {
                    GlobalInstance.Instance.InitializeSboComObject();
                }
                var bp = await repo.GetByCardCode(businessPartner.CardCode);

                string validationStr = ModelValidator.ValidateModel(businessPartner);

                if (!string.IsNullOrEmpty(validationStr))
                {
                    errMsg = string.Format(validationStr);
                    var resp = new HttpResponseMessage(HttpStatusCode.Conflict);
                    resp.Content      = new StringContent(errMsg);
                    resp.ReasonPhrase = "Object property validation error";
                    var err = ErrorLogger.Log(new ErrorLog
                    {
                        ErrorCode  = (int)HttpStatusCode.Conflict,
                        Message    = errMsg,
                        StackTrace = Environment.StackTrace
                    });

                    transactionLogger.LogBPTransaction(businessPartner, false, "A", this.Request.Headers.Host, err);
                    throw new HttpResponseException(resp);
                }

                if (businessPartner != null)
                {
                    errMsg = string.Format("Business partner {0} already exist.", businessPartner.CardCode);
                    var resp = new HttpResponseMessage(HttpStatusCode.Conflict);
                    resp.Content      = new StringContent(errMsg);
                    resp.ReasonPhrase = "Object already exist.";
                    var err = ErrorLogger.Log(new ErrorLog
                    {
                        ErrorCode  = (int)HttpStatusCode.Conflict,
                        Message    = errMsg,
                        StackTrace = Environment.StackTrace
                    });

                    transactionLogger.LogBPTransaction(businessPartner, false, "A", this.Request.Headers.Host, err);
                    throw new HttpResponseException(resp);
                }

                if (repo.Add(businessPartner) < 0)
                {
                    errMsg = GlobalInstance.Instance.SBOErrorMessage;
                    var resp = new HttpResponseMessage(HttpStatusCode.Conflict);
                    resp.Content      = new StringContent(errMsg);
                    resp.ReasonPhrase = "SBO Error";
                    var err = ErrorLogger.Log(new ErrorLog
                    {
                        ErrorCode  = (int)HttpStatusCode.Conflict,
                        Message    = errMsg,
                        StackTrace = Environment.StackTrace
                    });

                    transactionLogger.LogBPTransaction(businessPartner, true, "A", this.Request.Headers.Host, err);
                    throw new HttpResponseException(resp);
                }

                transactionLogger.LogBPTransaction(businessPartner, true, "A", this.Request.Headers.Host);
                return(Ok(string.Format("Business partner {0} succesfully added.", businessPartner.CardCode)));
            }
            catch (HttpResponseException ex)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
        }