Esempio n. 1
0
        /// <summary>
        /// Update detail entity data,
        /// Todo: For insert, need meet business rules and supply valid fields
        /// </summary>
        /// <param name="model"></param>
        private void UpdateDetailFields(T model)
        {
            if (model.CustomerOptionalFields != null)
            {
                foreach (var item in model.CustomerOptionalFields)
                {
                    var filter = "(IDCUST = \"" + item.CustomerNumber + "\") AND (OPTFIELD = \"" + item.OptionalField + "\")";
                    _detail.Browse(filter, true);

                    if (_detail.Fetch(false))
                    {
                        _detailMapper.Map(item, _detail);
                        if (model.HasChanged)
                        {
                            _detail.Update();
                        }
                        else if (model.IsDeleted)
                        {
                            _detail.Delete();
                        }
                    }
                    else
                    {
                        if (model.IsNewLine)
                        {
                            _detailMapper.Map(item, _detail);
                            _detail.Insert();
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Save Entity information
        /// Todo: For insert, need meet business rules and supply valid fields
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public override T Save(T model)
        {
            var filter = "(IDCUST = \"" + model.CustomerNumber + "\")";

            CreateBusinessEntities();
            // Update/insert header field
            _header.Browse(filter, true);
            if (_header.Fetch(false))
            {
                _headerMapper.Map(model, _header);
                _header.Update();
            }
            else
            {
                _headerMapper.Map(model, _header);
                _header.Insert();
            }

            //Update/insert detail fields
            if (model.CustomerOptionalFields != null)
            {
                UpdateDetailFields(model);
            }

            return(model);
        }
Esempio n. 3
0
 public virtual void Update(T entity)
 {
     if (entity == null)
     {
         throw new ArgumentNullException(nameof(entity));
     }
     _bizLayer.Update(entity);
 }
        /// <summary>
        /// Save Source Journal Profile
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public override T Save(T model)
        {
            _businessEntity = CreateBusinessEntities();

            var sourceCodes = model.SourceCodeList.Items.ToList();

            var sourceCodeCount = sourceCodes.Count;

            _businessEntity.SetValue(SourceJournalProfile.Fields.SourceJournalName, model.SourceJournalName);
            var exist = _businessEntity.Read(false);

            CheckETag(_businessEntity, model);

            for (var i = 1; i <= sourceCodeCount; i++)
            {
                var iStringVal = i.ToString(CultureInfo.InvariantCulture);

                string sourceLedgerColumnName;
                string sourceTypeColumnName;

                if (i <= 9)
                {
                    sourceLedgerColumnName = SourceLedgerFieldName + "0" + iStringVal;
                    sourceTypeColumnName   = SourceTypeFieldName + "0" + iStringVal;
                }
                else
                {
                    sourceLedgerColumnName = SourceLedgerFieldName + iStringVal;
                    sourceTypeColumnName   = SourceTypeFieldName + iStringVal;
                }

                var    sourceCode             = sourceCodes[i - 1].Source;
                string sourceLedgerFieldValue = string.Empty;
                string sourceTypeFieldValue   = string.Empty;

                if (!string.IsNullOrEmpty(sourceCode))
                {
                    if (!sourceCodes[i - 1].IsDeleted)
                    {
                        var source = sourceCode.Split('-');

                        if (source.Length > 1)
                        {
                            sourceLedgerFieldValue = source[0];
                            sourceTypeFieldValue   = source[1];
                        }
                        else
                        {
                            sourceLedgerFieldValue = sourceCode;
                        }
                    }
                }

                sourceLedgerFieldValue = sourceCodes[i - 1].IsDeleted ? string.Empty : sourceLedgerFieldValue;
                sourceTypeFieldValue   = sourceCodes[i - 1].IsDeleted ? string.Empty : sourceTypeFieldValue;

                _businessEntity.SetValue(sourceLedgerColumnName, sourceLedgerFieldValue);
                _businessEntity.SetValue(sourceTypeColumnName, sourceTypeFieldValue);
            }

            if (exist)
            {
                _businessEntity.Update();
            }
            else
            {
                _businessEntity.Insert();
            }

            model.ETag  = _businessEntity.ETag;
            model.Exist = true;

            return(model);
        }