public void UpdateParamatricBusinessRules_ParamatricBusinessRulesModelDto_NullDataBase()
        {
            var settingsMock = new Mock<ISettings>();
            var repositoryMock = new Mock<IRepository>();
            var uowMock = new Mock<IUnitOfWork>();
            var serviceLocatorMock = new Mock<IServiceLocator>();
            serviceLocatorMock.Setup(x => x.GetInstance<IRepository>())
                .Returns(repositoryMock.Object);
            serviceLocatorMock.Setup(x => x.GetInstance<IUnitOfWork>())
                .Returns(uowMock.Object);

            ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object);
            repositoryMock.Setup(r => r.CreateUnitOfWork()).Returns(uowMock.Object);

            Guid id = Guid.NewGuid();
            ParamatricBusinessRulesModelDto paramatricBusinessRulesModelDto =
                new ParamatricBusinessRulesModelDto
                {
                    CommissionLevels = "CommissionLevels".ToUpper(),
                    ExpiryTimeFrame = "ExpiryTimeFrame".ToUpper(),
                    FileUploadLimits = "FileUploadLimits".ToUpper(),
                    Margins = "Margins".ToUpper(),
                    MaximumBooking = "MaximumBooking".ToUpper(),
                    MaximumLeadTime = "MaximumLeadTime".ToUpper(),
                    MinimumBooking = "MinimumBooking".ToUpper(),
                    MinimumLeadTime = "MinimumLeadTime".ToUpper(),
                    NavigateHref = "NavigateHref".ToUpper()
                };

            // Act
            ManagementService managementService = new ManagementService(
                uowMock.Object, repositoryMock.Object, settingsMock.Object);
            managementService
                .UpdateParamatricBusinessRules(paramatricBusinessRulesModelDto);

            // Assert
                //Query
            repositoryMock.Verify(repo => repo.Query<SystemConfig>());

                //Insert
            repositoryMock.Verify(repo => repo.Insert<SystemConfig>(It.Is<SystemConfig>
                (s => s.Name == ParamatricBusinessRules.COMMISSION_LEVELS.ToString())));

            repositoryMock.Verify(repo => repo.Insert<SystemConfig>(It.Is<SystemConfig>
                (s => s.Name == ParamatricBusinessRules.EXPIRY_TIMEFRAME.ToString())));

            repositoryMock.Verify(repo => repo.Insert<SystemConfig>(It.Is<SystemConfig>
                (s => s.Name == ParamatricBusinessRules.FILE_UPLOAD_LIMITS.ToString())));

            repositoryMock.Verify(repo => repo.Insert<SystemConfig>(It.Is<SystemConfig>
                (s => s.Name == ParamatricBusinessRules.MAXIMUM_BOOKING.ToString())));

            repositoryMock.Verify(repo => repo.Insert<SystemConfig>(It.Is<SystemConfig>
                (s => s.Name == ParamatricBusinessRules.MAXIMUM_LEAD_TIME.ToString())));

            repositoryMock.Verify(repo => repo.Insert<SystemConfig>(It.Is<SystemConfig>
                (s => s.Name == ParamatricBusinessRules.MINIMUM_BOOKING.ToString())));

            repositoryMock.Verify(repo => repo.Insert<SystemConfig>(It.Is<SystemConfig>
                (s => s.Name == ParamatricBusinessRules.MINIMUM_LEAD_TIME.ToString())));

                //Save
            uowMock.Verify(uow => uow.Save());
        }
        public void UpdateParamatricBusinessRules(ParamatricBusinessRulesModelDto model)
        {
            // COMMISSION_LEVELS
            var systemConfig_COMMISSION_LEVELS = Repository.Query<SystemConfig>().FirstOrDefault(a => a.Name.Equals(ParamatricBusinessRules.COMMISSION_LEVELS.ToString()));
            if (systemConfig_COMMISSION_LEVELS != null)
            {
                systemConfig_COMMISSION_LEVELS.Value = Utilities.RemoveCommaSymbol(model.CommissionLevels);

                Repository.Update<SystemConfig>(systemConfig_COMMISSION_LEVELS);
            }
            else
            {
                systemConfig_COMMISSION_LEVELS = new SystemConfig()
                {
                    CreatedDate = DateTime.UtcNow,
                    ModifiedDate = DateTime.UtcNow,
                    Name = ParamatricBusinessRules.COMMISSION_LEVELS.ToString(),
                    Value = model.CommissionLevels.ToString()
                };

                Repository.Insert<SystemConfig>(systemConfig_COMMISSION_LEVELS);
            }

            var systemConfig_FILE_UPLOAD_LIMITS = Repository.Query<SystemConfig>().FirstOrDefault(a => a.Name.Equals(ParamatricBusinessRules.FILE_UPLOAD_LIMITS.ToString()));
            if (systemConfig_FILE_UPLOAD_LIMITS != null)
            {
                systemConfig_FILE_UPLOAD_LIMITS.Value = Utilities.RemoveCommaSymbol(model.FileUploadLimits);

                Repository.Update<SystemConfig>(systemConfig_FILE_UPLOAD_LIMITS);
            }
            else
            {
                systemConfig_FILE_UPLOAD_LIMITS = new SystemConfig()
                {
                    CreatedDate = DateTime.UtcNow,
                    ModifiedDate = DateTime.UtcNow,
                    Name = ParamatricBusinessRules.FILE_UPLOAD_LIMITS.ToString(),
                    Value = model.FileUploadLimits.ToString()
                };

                Repository.Insert<SystemConfig>(systemConfig_FILE_UPLOAD_LIMITS);
            }

            // BASIC_FEE
            var systemConfig_BASIC_FEE = Repository.Query<SystemConfig>().FirstOrDefault(a => a.Name.Equals(ParamatricBusinessRules.BASIC_FEE.ToString()));
            if (systemConfig_BASIC_FEE != null)
            {
                systemConfig_BASIC_FEE.Value = Utilities.RemoveCommaSymbol(model.BasicFee);

                Repository.Update<SystemConfig>(systemConfig_BASIC_FEE);
            }
            else
            {
                systemConfig_BASIC_FEE = new SystemConfig()
                {
                    CreatedDate = DateTime.UtcNow,
                    ModifiedDate = DateTime.UtcNow,
                    Name = ParamatricBusinessRules.BASIC_FEE.ToString(),
                    Value = model.BasicFee.ToString()
                };

                Repository.Insert<SystemConfig>(systemConfig_BASIC_FEE);
            }

            // STARTING_TIME
            var systemConfig_STARTING_TIME = Repository.Query<SystemConfig>().FirstOrDefault(a => a.Name.Equals(ParamatricBusinessRules.STARTING_TIME.ToString()));
            if (systemConfig_STARTING_TIME != null)
            {
                systemConfig_STARTING_TIME.Value = Utilities.RemoveCommaSymbol(model.StartingTime);

                Repository.Update<SystemConfig>(systemConfig_STARTING_TIME);
            }
            else
            {
                systemConfig_STARTING_TIME = new SystemConfig()
                {
                    CreatedDate = DateTime.UtcNow,
                    ModifiedDate = DateTime.UtcNow,
                    Name = ParamatricBusinessRules.STARTING_TIME.ToString(),
                    Value = model.StartingTime.ToString()
                };

                Repository.Insert<SystemConfig>(systemConfig_STARTING_TIME);
            }

            // MINIMUM_BOOKING
            var systemConfig_MINIMUM_BOOKING = Repository.Query<SystemConfig>().FirstOrDefault(a => a.Name.Equals(ParamatricBusinessRules.MINIMUM_BOOKING.ToString()));
            if (systemConfig_MINIMUM_BOOKING != null)
            {
                systemConfig_MINIMUM_BOOKING.Value = Utilities.RemoveCommaSymbol(model.MinimumBooking);

                Repository.Update<SystemConfig>(systemConfig_MINIMUM_BOOKING);
            }
            else
            {
                systemConfig_MINIMUM_BOOKING = new SystemConfig()
                {
                    CreatedDate = DateTime.UtcNow,
                    ModifiedDate = DateTime.UtcNow,
                    Name = ParamatricBusinessRules.MINIMUM_BOOKING.ToString(),
                    Value = model.MinimumBooking.ToString()
                };

                Repository.Insert<SystemConfig>(systemConfig_MINIMUM_BOOKING);
            }

            // MAXIMUM_BOOKING
            var systemConfig_MAXIMUM_BOOKING = Repository.Query<SystemConfig>().FirstOrDefault(a => a.Name.Equals(ParamatricBusinessRules.MAXIMUM_BOOKING.ToString()));
            if (systemConfig_MAXIMUM_BOOKING != null)
            {
                systemConfig_MAXIMUM_BOOKING.Value = Utilities.RemoveCommaSymbol(model.MaximumBooking);

                Repository.Update<SystemConfig>(systemConfig_MAXIMUM_BOOKING);
            }
            else
            {
                systemConfig_MAXIMUM_BOOKING = new SystemConfig()
                {
                    CreatedDate = DateTime.UtcNow,
                    ModifiedDate = DateTime.UtcNow,
                    Name = ParamatricBusinessRules.MAXIMUM_BOOKING.ToString(),
                    Value = model.MaximumBooking.ToString()
                };

                Repository.Insert<SystemConfig>(systemConfig_MAXIMUM_BOOKING);
            }

            // MINIMUM_LEAD_TIME
            var systemConfig_MINIMUM_LEAD_TIME = Repository.Query<SystemConfig>().FirstOrDefault(a => a.Name.Equals(ParamatricBusinessRules.MINIMUM_LEAD_TIME.ToString()));
            if (systemConfig_MINIMUM_LEAD_TIME != null)
            {
                systemConfig_MINIMUM_LEAD_TIME.Value = Utilities.RemoveCommaSymbol(model.MinimumLeadTime);

                Repository.Update<SystemConfig>(systemConfig_MINIMUM_LEAD_TIME);
            }
            else
            {
                systemConfig_MINIMUM_LEAD_TIME = new SystemConfig()
                {
                    CreatedDate = DateTime.UtcNow,
                    ModifiedDate = DateTime.UtcNow,
                    Name = ParamatricBusinessRules.MINIMUM_LEAD_TIME.ToString(),
                    Value = model.MinimumLeadTime.ToString()
                };

                Repository.Insert<SystemConfig>(systemConfig_MINIMUM_LEAD_TIME);
            }

            // MAXIMUM_LEAD_TIME
            var systemConfig_MAXIMUM_LEAD_TIME = Repository.Query<SystemConfig>().FirstOrDefault(a => a.Name.Equals(ParamatricBusinessRules.MAXIMUM_LEAD_TIME.ToString()));
            if (systemConfig_MAXIMUM_LEAD_TIME != null)
            {
                systemConfig_MAXIMUM_LEAD_TIME.Value = Utilities.RemoveCommaSymbol(model.MaximumLeadTime);

                Repository.Update<SystemConfig>(systemConfig_MAXIMUM_LEAD_TIME);
            }
            else
            {
                systemConfig_MAXIMUM_LEAD_TIME = new SystemConfig()
                {
                    CreatedDate = DateTime.UtcNow,
                    ModifiedDate = DateTime.UtcNow,
                    Name = ParamatricBusinessRules.MAXIMUM_LEAD_TIME.ToString(),
                    Value = model.MaximumLeadTime.ToString()
                };

                Repository.Insert<SystemConfig>(systemConfig_MAXIMUM_LEAD_TIME);
            }

            // MAXIMUM_LEAD_TIME
            var systemPrepaymentMinValue = Repository.Query<SystemConfig>().FirstOrDefault(a => a.Name.Equals(ParamatricBusinessRules.PREPAYMENT_MINIMUM_VALUE.ToString()));
            if (systemPrepaymentMinValue != null)
            {
                systemPrepaymentMinValue.Value = Utilities.RemoveCommaSymbol(model.PrepaymentMinimumValue);

                Repository.Update<SystemConfig>(systemPrepaymentMinValue);
            }
            else
            {
                systemPrepaymentMinValue = new SystemConfig()
                {
                    CreatedDate = DateTime.UtcNow,
                    ModifiedDate = DateTime.UtcNow,
                    Name = ParamatricBusinessRules.PREPAYMENT_MINIMUM_VALUE.ToString(),
                    Value = model.PrepaymentMinimumValue.ToString()
                };

                Repository.Insert<SystemConfig>(systemPrepaymentMinValue);
            }

            // DEFER_DAYS_FOR_RCTI
            var systemDeferDaysForRCTI = Repository.Query<SystemConfig>().FirstOrDefault(a => a.Name.Equals(ParamatricBusinessRules.DEFER_DAYS_FOR_RCTI.ToString()));
            if (systemDeferDaysForRCTI != null)
            {
                systemDeferDaysForRCTI.Value = Utilities.RemoveCommaSymbol(model.DeferredDaysForRCTI);

                Repository.Update<SystemConfig>(systemDeferDaysForRCTI);
            }
            else
            {
                systemDeferDaysForRCTI = new SystemConfig()
                {
                    CreatedDate = DateTime.UtcNow,
                    ModifiedDate = DateTime.UtcNow,
                    Name = ParamatricBusinessRules.DEFER_DAYS_FOR_RCTI.ToString(),
                    Value = model.DeferredDaysForRCTI.ToString()
                };

                Repository.Insert<SystemConfig>(systemDeferDaysForRCTI);
            }

            // TRANSCRIPTION COST
            var systemTranscriptionCost = Repository.Query<SystemConfig>().FirstOrDefault(a => a.Name.Equals(ParamatricBusinessRules.TRANSCRIPTION_COST.ToString()));
            if (systemTranscriptionCost != null)
            {
                systemTranscriptionCost.Value = Utilities.RemoveCommaSymbol(model.TranscriptionCost);

                Repository.Update<SystemConfig>(systemTranscriptionCost);
            }
            else
            {
                systemTranscriptionCost = new SystemConfig()
                {
                    CreatedDate = DateTime.UtcNow,
                    ModifiedDate = DateTime.UtcNow,
                    Name = ParamatricBusinessRules.TRANSCRIPTION_COST.ToString(),
                    Value = model.DeferredDaysForRCTI.ToString()
                };

                Repository.Insert<SystemConfig>(systemTranscriptionCost);
            }

            // GST
            var systemGST = Repository.Query<SystemConfig>().FirstOrDefault(a => a.Name.Equals(ParamatricBusinessRules.GST_RATE.ToString()));
            if (systemGST != null)
            {
                systemGST.Value = Utilities.RemoveCommaSymbol(model.GST);

                Repository.Update<SystemConfig>(systemGST);
            }
            else
            {
                systemGST = new SystemConfig()
                {
                    CreatedDate = DateTime.UtcNow,
                    ModifiedDate = DateTime.UtcNow,
                    Name = ParamatricBusinessRules.GST_RATE.ToString(),
                    Value = model.GST.ToString()
                };

                Repository.Insert<SystemConfig>(systemGST);
            }

            // VOICE_IN_CONFERENCE
            var systemVoiceInConference = Repository.Query<SystemConfig>().FirstOrDefault(a => a.Name.Equals(ParamatricBusinessRules.VOICE_IN_CONFERENCE.ToString()));
            if (systemVoiceInConference != null)
            {
                systemVoiceInConference.Value = Utilities.RemoveCommaSymbol(model.Voice);

                Repository.Update<SystemConfig>(systemVoiceInConference);
            }
            else
            {
                systemVoiceInConference = new SystemConfig()
                {
                    CreatedDate = DateTime.UtcNow,
                    ModifiedDate = DateTime.UtcNow,
                    Name = ParamatricBusinessRules.VOICE_IN_CONFERENCE.ToString(),
                    Value = model.Voice.ToString()
                };

                Repository.Insert<SystemConfig>(systemVoiceInConference);
            }

            // LANGUAGE_IN_CONFERENCE
            var systemLanguageInConference = Repository.Query<SystemConfig>().FirstOrDefault(a => a.Name.Equals(ParamatricBusinessRules.LANGUAGE_IN_CONFERENCE.ToString()));
            if (systemLanguageInConference != null)
            {
                systemLanguageInConference.Value = Utilities.RemoveCommaSymbol(model.Language);

                Repository.Update<SystemConfig>(systemLanguageInConference);
            }
            else
            {
                systemLanguageInConference = new SystemConfig()
                {
                    CreatedDate = DateTime.UtcNow,
                    ModifiedDate = DateTime.UtcNow,
                    Name = ParamatricBusinessRules.LANGUAGE_IN_CONFERENCE.ToString(),
                    Value = model.Language.ToString()
                };

                Repository.Insert<SystemConfig>(systemLanguageInConference);
            }

            UnitOfWork.Save();
        }
        public ActionResult ParametricBusinessRules(ParamatricBusinessRulesModelDto model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var isValidModel = true;

                    if (model.MaximumBooking.Equals("0"))
                    {
                        ModelState["MaximumBooking"].Errors.Clear();
                        ModelState.AddModelError("MaximumBooking", "The value must be greater than zero.");
                        isValidModel = false;
                    }

                    if (model.MinimumBooking.Equals("0"))
                    {
                        ModelState["MinimumBooking"].Errors.Clear();
                        ModelState.AddModelError("MinimumBooking", "The value must be greater than zero.");
                        isValidModel = false;
                    }

                    if (model.MaximumLeadTime.Equals("0"))
                    {
                        ModelState["MaximumLeadTime"].Errors.Clear();
                        ModelState.AddModelError("MaximumLeadTime", "The value must be greater than zero.");
                        isValidModel = false;
                    }

                    if (model.MinimumLeadTime.Equals("0"))
                    {
                        ModelState["MinimumLeadTime"].Errors.Clear();
                        ModelState.AddModelError("MinimumLeadTime", "The value must be greater than zero.");
                        isValidModel = false;
                    }

                    if (model.PrepaymentMinimumValue.Equals("0"))
                    {
                        ModelState["PrepaymentMinimumValue"].Errors.Clear();
                        ModelState.AddModelError("PrepaymentMinimumValue", "The value must be greater than zero.");
                        isValidModel = false;
                    }

                    if (model.DeferredDaysForRCTI.Equals("0"))
                    {
                        ModelState["DeferredDaysForRCTI"].Errors.Clear();
                        ModelState.AddModelError("DeferredDaysForRCTI", "The value must be greater than zero.");
                        isValidModel = false;
                    }

                    if (model.GST.Equals("0"))
                    {
                        ModelState["GST"].Errors.Clear();
                        ModelState.AddModelError("GST", "The value must be greater than zero.");
                        isValidModel = false;
                    }

                    if (model.TranscriptionCost.Equals("0"))
                    {
                        ModelState["TranscriptionCost"].Errors.Clear();
                        ModelState.AddModelError("TranscriptionCost", "The value must be greater than zero.");
                        isValidModel = false;
                    }

                    if (string.IsNullOrEmpty(model.Voice))
                    {
                        ModelState["Voice"].Errors.Clear();
                        ModelState.AddModelError("Voice", "The value required..");
                        isValidModel = false;
                    }

                    if (string.IsNullOrEmpty(model.Language))
                    {
                        ModelState["Language"].Errors.Clear();
                        ModelState.AddModelError("Language", "The value required..");
                        isValidModel = false;
                    }

                    if (!isValidModel)
                    {
                        return View(model);
                    }

                    AdminServices.ManagementService.UpdateParamatricBusinessRules(model);

                    if (!string.IsNullOrEmpty(model.NavigateHref))
                    {
                        return Redirect(model.NavigateHref);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error("ParametricBusinessRules: " + ex.ToString());
                return View("Error");
            }
            //model.SubscriptionFees.Replace(",", "");
            model.CommissionLevels.Replace(",", "");
            //model.Margins.Replace(",", "");
            //model.FileUploadLimits.Replace(",", "");
            //model.ExpiryTimeFrame.Replace(",", "");
            model.MinimumBooking.Replace(",", "");
            model.MaximumBooking.Replace(",", "");
            model.MinimumLeadTime.Replace(",", "");
            model.MaximumLeadTime.Replace(",", "");

            //model.VirtualConsultaionCost.Replace(",", "");
            //model.VirtualConsultaionMargin.Replace(",", "");
            model.DeferredDaysForRCTI.Replace(",", "");
            model.BasicFee.Replace(",", "");
            model.StartingTime.Replace(",", "");

            return View(model);
        }
        public ParamatricBusinessRulesModelDto GetParamatricBusinessRules()
        {
            var result = new ParamatricBusinessRulesModelDto();

            var systemConfig = Repository.Query<SystemConfig>();

            if (systemConfig != null && systemConfig.Any())
            {
                foreach (var item in systemConfig)
                {
                    switch ((ParamatricBusinessRules)Enum.Parse(typeof(ParamatricBusinessRules), item.Name))
                    {
                        case ParamatricBusinessRules.COMMISSION_LEVELS:
                            result.CommissionLevels = item.Value;
                            break;

                        case ParamatricBusinessRules.FILE_UPLOAD_LIMITS:
                            result.FileUploadLimits = item.Value;
                            break;

                        case ParamatricBusinessRules.EXPIRY_TIMEFRAME:
                            break;

                        case ParamatricBusinessRules.MINIMUM_BOOKING:
                            result.MinimumBooking = item.Value;
                            break;

                        case ParamatricBusinessRules.MAXIMUM_BOOKING:
                            result.MaximumBooking = item.Value;
                            break;

                        case ParamatricBusinessRules.MINIMUM_LEAD_TIME:
                            result.MinimumLeadTime = item.Value;
                            break;

                        case ParamatricBusinessRules.MAXIMUM_LEAD_TIME:
                            result.MaximumLeadTime = item.Value;
                            break;

                        case ParamatricBusinessRules.BASIC_FEE:
                            result.BasicFee = item.Value;
                            break;

                        case ParamatricBusinessRules.STARTING_TIME:
                            result.StartingTime = item.Value;
                            break;

                        case ParamatricBusinessRules.PREPAYMENT_MINIMUM_VALUE:
                            result.PrepaymentMinimumValue = item.Value;
                            break;

                        case ParamatricBusinessRules.DEFER_DAYS_FOR_RCTI:
                            result.DeferredDaysForRCTI = item.Value;
                            break;

                        case ParamatricBusinessRules.TRANSCRIPTION_COST:
                            result.TranscriptionCost = item.Value;
                            break;

                        case ParamatricBusinessRules.GST_RATE:
                            result.GST = item.Value;
                            break;

                        case ParamatricBusinessRules.VOICE_IN_CONFERENCE:
                            result.Voice = item.Value;
                            break;

                        case ParamatricBusinessRules.LANGUAGE_IN_CONFERENCE:
                            result.Language = item.Value;
                            break;
                    }
                }
            }

            return result;
        }