Beispiel #1
0
        /// <summary>
        /// Add Tariff Rate
        /// </summary>
        /// <param name="standardRateMain"></param>
        /// <returns></returns>
        public TariffRateContent SaveTariffRate(StandardRateMain standardRateMain)
        {
            TariffType tariffType = tariffTypeRepository.Find(long.Parse(standardRateMain.TariffTypeCode));

            standardRateMain.TariffTypeCode = tariffType.TariffTypeCode;

            #region Add
            if (standardRateMain.StandardRtMainId == 0)
            {
                StandardRateValidation(standardRateMain, true);
                standardRateMain.UserDomainKey    = standardRateMainRepository.UserDomainKey;
                standardRateMain.IsActive         = true;
                standardRateMain.IsDeleted        = false;
                standardRateMain.IsPrivate        = false;
                standardRateMain.IsReadOnly       = false;
                standardRateMain.RecCreatedDt     = DateTime.Now;
                standardRateMain.RecLastUpdatedDt = DateTime.Now;
                standardRateMain.RecCreatedBy     = standardRateMainRepository.LoggedInUserIdentity;
                standardRateMain.RecLastUpdatedBy = standardRateMainRepository.LoggedInUserIdentity;
                standardRateMain.RowVersion       = 0;
                //set child (Standard Rate in Standard Rate Main) properties
                #region Standard Rate in Standard Rate Main

                if (standardRateMain.StandardRates != null)
                {
                    // set properties
                    foreach (StandardRate item in standardRateMain.StandardRates)
                    {
                        item.IsActive         = true;
                        item.IsDeleted        = false;
                        item.IsPrivate        = false;
                        item.IsReadOnly       = false;
                        item.RecCreatedDt     = DateTime.Now;
                        item.RecLastUpdatedDt = DateTime.Now;
                        item.RecCreatedBy     = standardRateMainRepository.LoggedInUserIdentity;
                        item.RecLastUpdatedBy = standardRateMainRepository.LoggedInUserIdentity;
                        item.UserDomainKey    = standardRateMainRepository.UserDomainKey;
                    }
                }

                #endregion
                standardRateMainRepository.Add(standardRateMain);
                standardRateMainRepository.SaveChanges();
            }
            #endregion

            #region Edit
            else
            {
                StandardRateValidation(standardRateMain, false);
                if (standardRateMain.StandardRates != null)
                {
                    foreach (StandardRate standardRate in standardRateMain.StandardRates)
                    {
                        standardRate.IsActive         = true;
                        standardRate.IsDeleted        = false;
                        standardRate.IsPrivate        = false;
                        standardRate.IsReadOnly       = false;
                        standardRate.RecCreatedDt     = DateTime.Now;
                        standardRate.RecLastUpdatedDt = DateTime.Now;
                        standardRate.RecCreatedBy     = standardRateMainRepository.LoggedInUserIdentity;
                        standardRate.RecLastUpdatedBy = standardRateMainRepository.LoggedInUserIdentity;
                        standardRate.UserDomainKey    = standardRateMainRepository.UserDomainKey;
                        standardRate.StandardRtMainId = standardRateMain.StandardRtMainId;
                        if (standardRate.StandardRtId > 0)
                        {
                            long oldRecordId = standardRate.StandardRtId;
                            standardRate.StandardRtId   = 0;
                            standardRate.RevisionNumber = standardRate.RevisionNumber + 1;
                            standardRateRepository.Add(standardRate);
                            standardRateRepository.SaveChanges();
                            StandardRate oldStandardRate = standardRateRepository.Find(oldRecordId);
                            oldStandardRate.ChildStandardRtId = standardRate.StandardRtId;
                            standardRateRepository.SaveChanges();
                        }
                        else
                        {
                            standardRateRepository.Add(standardRate);
                            standardRateRepository.SaveChanges();
                        }
                    }
                }
            }
            #endregion

            return(new TariffRateContent
            {
                StandardRtMainId = standardRateMain.StandardRtMainId,
                StandardRtMainCode = standardRateMain.StandardRtMainCode,
                StandardRtMainName = standardRateMain.StandardRtMainName,
                StandardRtMainDescription = standardRateMain.StandardRtMainDescription,
                StartDt = standardRateMain.StartDt,
                EndDt = standardRateMain.EndDt,
                TariffTypeId = tariffType.TariffTypeId,
                TariffTypeCodeName = tariffType.TariffTypeCode + " - " + tariffType.TariffTypeName,
                OperationId = tariffType.OperationId,
                OperationCodeName =
                    tariffType.Operation.OperationCode + " - " + tariffType.Operation.OperationName,
            });
        }