Exemple #1
0
        /// <summary>
        /// Get the source code based on primary key
        /// </summary>
        /// <param name="sourceLedger">Source Ledger</param>
        /// <param name="sourceType">Source Type</param>
        /// <returns>Source Code</returns>
        public T GetByIds(string sourceLedger, string sourceType)
        {
            _businessEntity = CreateBusinessEntities();
            CheckRights(_businessEntity, SecurityType.Inquire);

            _businessEntity.SetValue(SourceCode.Fields.SourceLedger, sourceLedger);
            _businessEntity.SetValue(SourceCode.Fields.SourceType, sourceType);
            if (!_businessEntity.Read(false))
            {
                return(null);
            }
            var sourceCodeMapper = new SourceCodeMapper <T>(Context);

            return(sourceCodeMapper.Map(_businessEntity));
        }
        /// <summary>
        /// GetById
        /// </summary>
        /// <typeparam name="TKey">Key</typeparam>
        /// <param name="id">Id</param>
        /// <returns>T</returns>
        public override T GetById <TKey>(TKey id)
        {
            _businessEntity = CreateBusinessEntities();
            CheckRights(_businessEntity, SecurityType.Inquire);

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

            return(new T
            {
                SourceJournalName = _businessEntity.GetValue <string>(SourceJournalProfile.Index.SourceJournalName),
                ETag = _businessEntity.ETag,
                Exist = exist
            });
        }
Exemple #3
0
        /// <summary>
        /// Method to Add Receipt detail.
        /// </summary>
        /// <param name="detailEntity">Detail Entity</param>
        /// <param name="lineNumber">Line Number</param>
        /// <param name="receiptDetail">Receipt Detail</param>
        /// <returns>Line Number</returns>
        private int AddReceiptDetail(IBusinessEntity detailEntity, int lineNumber, List <ReceiptDetail> receiptDetail)
        {
            var firstItem = _detailMapper.Map(detailEntity);

            // Set the pointer to the current row
            _detailMapper.MapKey(firstItem, detailEntity);
            var isSuccess = detailEntity.Read(false);

            firstItem.LineNumber = lineNumber;
            if (isSuccess)
            {
                receiptDetail.Add(firstItem);
            }

            lineNumber++;
            return(lineNumber);
        }
        /// <summary>
        /// Delete
        /// </summary>
        /// <param name="id">Source Journal Name</param>
        /// <returns>SourceJournalProfile</returns>
        public T Delete(string id)
        {
            _businessEntity = CreateBusinessEntities();
            _businessEntity.SetValue(SourceJournalProfile.Fields.SourceJournalName, id);

            if (_businessEntity.Read(false))
            {
                _businessEntity.Delete();
            }
            else
            {
                throw ExceptionHelper.RowNotFoundException(CommonResx.DeleteFailedNoRecordMessage);
            }

            _businessEntity.Cancel();

            var mapper = new SourceJournalProfileMapper <T>(_context);

            return(mapper.Map(_businessEntity));
        }
        /// <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);
        }
        /// <summary>
        /// Gets SourceJournal Detail
        /// </summary>
        /// <param name="id">sourceJournalName</param>
        /// <param name="pageNumber"></param>
        /// <param name="pageSize"></param>
        public EnumerableResponse <SourceCode> GetSourceJournal(string id, int pageNumber, int pageSize)
        {
            _businessEntity = CreateBusinessEntities();

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

            var sourceJournal = new List <SourceCode>();

            int dataIndex = 1;

            var totalResultCount = 0;

            if (exist)
            {
                for (var i = 1; i <= SourceJournalProfileCount; 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 sourceLedger = _businessEntity.GetValue <string>(sourceLedgerColumnName);
                    var sourceType   = _businessEntity.GetValue <string>(sourceTypeColumnName);

                    if (!string.IsNullOrEmpty(sourceLedger) && !string.IsNullOrEmpty(sourceType))
                    {
                        using (var sourceCodeRepository = Resolve <ISourceCodeEntity <SourceCode> >())
                        {
                            var sourceCode = sourceCodeRepository.GetByIds(sourceLedger, sourceType);
                            var source     = sourceLedger + "-" + sourceType;
                            sourceCode.Source = source;
                            sourceCode.PreviousSourceValue = source;
                            sourceCode.SerialNumber        = dataIndex;
                            sourceCode.DisplayIndex        = dataIndex;
                            sourceJournal.Add(sourceCode);
                        }

                        totalResultCount = totalResultCount + 1;
                    }
                    else
                    {
                        break;
                    }

                    dataIndex = dataIndex + 1;
                }
            }

            //If Page size and Page Numer is -1 - Send all the records
            if (sourceJournal.Count > 0 && (pageSize >= 0 && pageNumber >= 0))
            {
                sourceJournal = sourceJournal.Skip(pageNumber * pageSize).Take(pageSize).ToList();
            }

            return(new EnumerableResponse <SourceCode> {
                Items = sourceJournal, TotalResultsCount = totalResultCount
            });
        }