public void Save(AgrimanagrSettingsViewModel model)
 {
     var settings = ConstructAppSettings(model);
     foreach (var setting in settings)
     {
         _settingsRepository.Save(setting);
     }
 }
Ejemplo n.º 2
0
 public ActionResult Settings(AgrimanagrSettingsViewModel model)
 {
     try
     {
         _settingsViewModelBuilder.Save(model);
         TempData["msg"] = "Settings Successfully Saved";
         return RedirectToAction("Settings");
     }
     catch (DomainValidationException ve)
     {
         ValidationSummary.DomainValidationErrors(ve, ModelState);
         TempData["msg"] = "Validation Errors, Unable to save settings\n"+ve.Message;
     }
     catch (Exception ex)
     {
         TempData["msg"] = "Error saving Agrimanagr Settings\nDetails:" + ex.Message;
     }
     return View(model);
 }
        private IEnumerable<AppSettings> ConstructAppSettings(AgrimanagrSettingsViewModel model)
        {
            var settingenums = new List<SettingsKeys>();
            settingenums.Add(SettingsKeys.CompanyName);
            settingenums.Add(SettingsKeys.CompanyDetails);
            settingenums.Add(SettingsKeys.ShowDispatchPage);
            settingenums.Add(SettingsKeys.ShowServiceProvderOnPurchase);
            settingenums.Add(SettingsKeys.ShowDeliveryDetails);
            settingenums.Add(SettingsKeys.ShowLoadingDetails);
            settingenums.Add(SettingsKeys.Traceable);
            settingenums.Add(SettingsKeys.ShowDeliveredBy);
            settingenums.Add(SettingsKeys.WeighingContainerForStorage);
            settingenums.Add(SettingsKeys.EnforceNoOfContainers);
            settingenums.Add(SettingsKeys.EnforceWeighingOnReception);
            settingenums.Add(SettingsKeys.NotificationOnWeighing);
            settingenums.Add(SettingsKeys.LoadBatches);
            settingenums.Add(SettingsKeys.SetPurchasingClerkAsDriver);
            settingenums.Add(SettingsKeys.AllowManualEntryOfWeight);
            settingenums.Add(SettingsKeys.ShowCumulativeWeightOnReceipts);
            settingenums.Add(SettingsKeys.EnforceVehicleMileageAndTime);
            settingenums.Add(SettingsKeys.RestrictPurchaseFromSubsequentCentres);
            settingenums.Add(SettingsKeys.EnforcePasswordChange);
            settingenums.Add(SettingsKeys.EnforceGps);
            settingenums.Add(SettingsKeys.EnforceTransactionalWeightLimit);
            settingenums.Add(SettingsKeys.HideContainerNumber);
            settingenums.Add(SettingsKeys.ShowWarehouseReceipt);
            settingenums.Add(SettingsKeys.ShowFarmActivities);
            settingenums.Add(SettingsKeys.EnforceHideFarmOnPhone);

            var items = new List<AppSettings>();
            foreach (var settingenum in settingenums)
            {
                var setting = new AppSettings(Guid.NewGuid());

                setting.Key = settingenum;
                setting.VirtualCityAppName = VirtualCityApp.Agrimanagr.ToString();
                switch ((SettingsKeys)Enum.Parse(typeof(SettingsKeys), settingenum.ToString()))
                {

                    case SettingsKeys.CompanyDetails:
                        setting.Value = model.CompanyDetails ?? "";
                        break;
                    case SettingsKeys.CompanyName:
                        setting.Value = model.CompanyName ?? "";
                        break;
                    case SettingsKeys.ShowDeliveredBy:
                        setting.Value = model.ShowDeliveredBy.ToString();

                        break;
                    case SettingsKeys.ShowDeliveryDetails:
                        setting.Value = model.ShowDeliveryDetails.ToString();

                        break;
                    case SettingsKeys.ShowServiceProvderOnPurchase:
                        setting.Value = model.ShowServiceProvderOnPurchase.ToString();

                        break;
                    case SettingsKeys.ShowLoadingDetails:
                        setting.Value = model.ShowLoadingDetails.ToString();

                        break;
                    case SettingsKeys.ShowDispatchPage:
                        setting.Value = model.ShowDispatchPage.ToString();

                        break;
                    case SettingsKeys.EnforceNoOfContainers:
                        setting.Value = model.EnforceNoOfContainers.ToString();

                        break;
                    case SettingsKeys.NotificationOnWeighing:
                        setting.Value = model.NotificationOnWeighing.ToString();

                        break;
                    case SettingsKeys.WeighingContainerForStorage:
                        setting.Value = model.WeighingContainerForStorage.ToString();

                        break;
                    case SettingsKeys.EnforceVehicleMileageAndTime:
                        setting.Value = model.EnforceVehicleMileageAndTime.ToString();
                        break;

                    case SettingsKeys.LoadBatches:
                        setting.Value = model.LoadBatches.ToString();
                        break;
                    case SettingsKeys.Traceable:
                        setting.Value = model.Traceable.ToString();
                        break;
                    case SettingsKeys.SetPurchasingClerkAsDriver:
                        setting.Value = model.SetPurchasingClerkAsDriver.ToString();
                        break;

                    case SettingsKeys.EnforceWeighingOnReception:
                        setting.Value = model.EnforceWeighingOnReception.ToString();
                        break;
                    case SettingsKeys.AllowManualEntryOfWeight:
                        setting.Value = model.AllowManualEntryOfWeight.ToString();
                        break;
                    case SettingsKeys.ShowCumulativeWeightOnReceipts:
                        setting.Value = model.ShowCumulativeWeightsOnReceipts.ToString();
                        break;
                    case SettingsKeys.RestrictPurchaseFromSubsequentCentres:
                        setting.Value = model.RestrictPurchaseFromSubsequentCentres.ToString();
                        break;
                    case SettingsKeys.EnforcePasswordChange:
                        setting.Value = model.EnforcePasswordChange.ToString();
                        break;
                    case SettingsKeys.EnforceGps:
                        setting.Value = model.EnforceGps.ToString();
                        break;
                    case SettingsKeys.EnforceTransactionalWeightLimit:
                        setting.Value = model.EnforceTransactionalWeightLimit + "," + "Min:(" + model.MinimumWeightLimit + ")," + "Max:(" + model.MaximumWeightLimit + ")";
                       // var val = setting.Value;
                        if (model.EnforceTransactionalWeightLimit ==false)
                        {
                            setting.Value = model.EnforceTransactionalWeightLimit + "," + "Min:(" + 0.0 + ")," + "Max:(" + 0.0 + ")";
                        }
                      
                        break;
                    case SettingsKeys.HideContainerNumber:
                        setting.Value = model.HideContainerNumber.ToString();
                        break;
                    case SettingsKeys.ShowFarmActivities:
                        setting.Value = model.ShowFarmActivities.ToString();
                        break;
                    case SettingsKeys.ShowWarehouseReceipt:
                        setting.Value = model.ShowWarehouseReceipt.ToString();
                        break;
                    case SettingsKeys.EnforceHideFarmOnPhone:
                        setting.Value = model.EnforceHideFarmOnPhone.ToString();
                        break;
                }
                if (!items.Any(p => p.Key == setting.Key))
                    items.Add(setting);
            }
            return items.AsEnumerable();
        }
        private AgrimanagrSettingsViewModel CreateViewModel(IEnumerable<AppSettings> settings)
        {

            var model = new AgrimanagrSettingsViewModel();

            foreach (var appSetting in settings)
            {
                switch (appSetting.Key)
                {
                    case SettingsKeys.CompanyDetails:
                        model.CompanyDetails = appSetting.Value;
                        break;
                    case SettingsKeys.CompanyName:
                        model.CompanyName = appSetting.Value;
                        break;
                    case SettingsKeys.EnforceNoOfContainers:
                        model.EnforceNoOfContainers = bool.Parse(appSetting.Value);
                        break;
                    case SettingsKeys.WeighingContainerForStorage:
                        model.WeighingContainerForStorage = bool.Parse(appSetting.Value);
                        break;
                    case SettingsKeys.ShowDeliveredBy:
                        model.ShowDeliveredBy = bool.Parse(appSetting.Value);
                        break;
                    case SettingsKeys.Traceable:
                        model.Traceable = Boolean.Parse(appSetting.Value);
                        break;
                    case SettingsKeys.ShowLoadingDetails:
                        model.ShowLoadingDetails = Boolean.Parse(appSetting.Value);
                        break;
                    case SettingsKeys.ShowServiceProvderOnPurchase:
                        model.ShowServiceProvderOnPurchase = Boolean.Parse(appSetting.Value);
                        break;
                    case SettingsKeys.ShowDispatchPage:
                        model.ShowDispatchPage = Boolean.Parse(appSetting.Value);
                        break;
                    case SettingsKeys.NotificationOnWeighing:
                        model.NotificationOnWeighing = Boolean.Parse(appSetting.Value);
                        break;
                    case SettingsKeys.SetPurchasingClerkAsDriver:
                        model.SetPurchasingClerkAsDriver = Boolean.Parse(appSetting.Value);
                        break;
                    case SettingsKeys.EnforceWeighingOnReception:
                        model.EnforceWeighingOnReception = Boolean.Parse(appSetting.Value);
                        break;
                    case SettingsKeys.AllowManualEntryOfWeight:
                        model.AllowManualEntryOfWeight = Boolean.Parse(appSetting.Value);
                        break;
                    case SettingsKeys.ShowCumulativeWeightOnReceipts:
                        model.ShowCumulativeWeightsOnReceipts = Boolean.Parse(appSetting.Value);
                        break;
                    case SettingsKeys.EnforceVehicleMileageAndTime:
                        model.EnforceVehicleMileageAndTime = Boolean.Parse(appSetting.Value);
                        break;
                    case SettingsKeys.RestrictPurchaseFromSubsequentCentres:
                        model.RestrictPurchaseFromSubsequentCentres = Boolean.Parse(appSetting.Value);
                        break;
                    case SettingsKeys.EnforcePasswordChange:
                        model.EnforcePasswordChange = Boolean.Parse(appSetting.Value);
                        break;
                    case SettingsKeys.EnforceGps:
                        model.EnforceGps = Boolean.Parse(appSetting.Value);
                        break;
                    case SettingsKeys.EnforceTransactionalWeightLimit:
                        var val = appSetting.Value;
                        string value = val.StartsWith("False") ? "False" : "True";
                        model.EnforceTransactionalWeightLimit = Boolean.Parse(value);

                        StringCollection information = new StringCollection();
                        foreach (Match match in Regex.Matches(val, @"\(([^)]*)\)"))
                        {
                            information.Add(match.Value);
                        }
                        var minValue = information[0].Trim();
                        minValue = minValue.Replace("(", string.Empty).Replace(")", string.Empty);
                        string maxValue = information[1].Trim();
                        maxValue = maxValue.Replace("(", string.Empty).Replace(")", string.Empty);
                        double mn = double.Parse(minValue);
                        double mx = double.Parse(maxValue);
                        model.MinimumWeightLimit = mn;
                        model.MaximumWeightLimit = mx;
                        break;
                    case SettingsKeys.HideContainerNumber:
                        model.HideContainerNumber = Boolean.Parse(appSetting.Value);
                        break;
                    case SettingsKeys.ShowFarmActivities:
                        model.ShowFarmActivities = Boolean.Parse(appSetting.Value);
                        break;
                    case SettingsKeys.ShowWarehouseReceipt:
                        model.ShowWarehouseReceipt = Boolean.Parse(appSetting.Value);
                        break;

                    case SettingsKeys.EnforceHideFarmOnPhone:
                        model.EnforceHideFarmOnPhone = Boolean.Parse(appSetting.Value);
                        break;
                }
            }

            return model;
        }