Beispiel #1
0
        public async Task <int> UpdateSetting(Appsetting entity)
        {
            int result = 0;

            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }

            entities.Attach(entity);
            _DBContext.Entry(entity).State = EntityState.Modified;
            result = await _DBContext.SaveChangesAsync();

            return(result);
        }
Beispiel #2
0
        static public void LoadJson(string envName)
        {
            var parList = new ParamList();

            using (var r = new StreamReader(@"D:\Projects\ConfigHelper\input\paramList.json"))
            {
                string json = r.ReadToEnd();
                //List<Param> items = JsonConvert.DeserializeObject<List<Param>>(json);
                parList = JsonConvert.DeserializeObject <ParamList>(json);
            }

            var par = parList.env.Where(x => x.environment == envName).First();

            //envName

            var settings = new Appsetting();

            using (var r = new StreamReader(@"D:\Projects\ConfigHelper\input\appsettings.json"))
            {
                string json = r.ReadToEnd();
                //var items1 = JsonConvert.DeserializeObject<List<Item>>(json);
                settings = JsonConvert.DeserializeObject <Appsetting>(json);
            }

            settings.ConnectionStrings.DefaultConnection = par.connectionString;

            JsonSerializer serializer = new JsonSerializer();

            serializer.NullValueHandling = NullValueHandling.Ignore;

            using (StreamWriter sw = new StreamWriter($@"D:\Projects\ConfigHelper\input\appsettings.{envName}.json"))
                using (JsonWriter writer = new JsonTextWriter(sw))
                {
                    serializer.Serialize(writer, settings);
                    // {"ExpiryDate":new Date(1230375600000),"Price":0}
                }

            // 1. read appsetting file
            // 2. create model appsetting
            // 3. seve file appsetting.Test.json
        }
Beispiel #3
0
        public async Task <int> InsertSetting(string Key, string Value)
        {
            int result = 0;

            if (string.IsNullOrEmpty(Key))
            {
                throw new ArgumentNullException("entity");
            }

            Appsetting DBEntity = new Appsetting
            {
                Id     = 0,
                AppKey = Key,
                AppVal = Value
            };

            entities.Add(DBEntity);
            result = await _DBContext.SaveChangesAsync();

            return(result);
        }
        public ActionResult Create([Bind(Include = "NOMBRE,VALUE,ACTIVO")] Appsetting appsetting)
        {
            APPSETTING u      = new APPSETTING();
            string     nOMBRE = appsetting.NOMBRE.Replace(" ", "_");

            u.NOMBRE = nOMBRE;
            u.VALUE  = appsetting.VALUE;
            u.ACTIVO = true;

            db.APPSETTINGs.Add(u);

            try
            {
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            catch {
                ViewBag.Error = "El usuario ya existe. Introduzca un ID de usuario diferente";
                int pagina = 923; //ID EN BASE DE DATOS
                FnCommon.ObtenerConfPage(db, pagina, User.Identity.Name, this.ControllerContext.Controller);
                return(View());
            }
        }
        static void Main()
        {
            // Example based on products.json
            var product = new Product()
            {
                Id            = 12,
                Name          = "Example product",
                ColorVariants = new List <ColorVariant>()
                {
                    new ColorVariant()
                    {
                        VariantId = 10,
                        Color     = "Green"
                    },
                    new ColorVariant()
                    {
                        VariantId = 12,
                        Color     = "Red"
                    }
                }
            };

            var x = product.Demo;

            var date = product.At;

            Console.WriteLine($"id={product.Id}");
            Console.WriteLine($"name={product.Name}");

            // Example of configuration
            IConfiguration config = new ConfigurationBuilder()
                                    .AddJsonFile("appsettings.json")
                                    .Build();

            Console.WriteLine($"Regular way using magic strings: {config.GetSection("Something").GetSection("SomeValue").Value}");
            Console.WriteLine($"Typed way: {Appsetting.FromConfig(config).Something.SomeValue}");
        }
Beispiel #6
0
 public UserService(APIDataContext dbContext, IUnitOfWork unitOfWork, IOptions <Appsetting> appsetting)
 {
     _unitOfWork = unitOfWork;
     _appsetting = appsetting.Value;
     _dbContext  = dbContext;
 }
Beispiel #7
0
 public WeatherForecastController(IConfiguration configuration, ILogger <WeatherForecastController> logger, IOptionsSnapshot <Appsetting> options)
 {
     _appsetting = options.Value;
     var key = configuration.GetSection("Appsetting:key");
 }
Beispiel #8
0
 public ValuesController(IOptionsSnapshot <Appsetting> optionsSnapshot)
 {
     _appsetting = optionsSnapshot.Value;
 }