AppSettingsController.cs 2.51 KB
using DentalDecks.Server.Models;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace DentalDecks.Server.Controllers
{
    public class AppSettingsController : ApiController
    {
        // GET: api/AppSettings
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }

        // GET: api/AppSettings/5
        public HttpResponseMessage Get(string applicationName, string userId)
        {
            HttpResponseMessage response = Request.CreateResponse();
            try
            {
                dynamic appSettings = ApplicationSettings.GetApplicationSettings(applicationName, userId);

                response.StatusCode = HttpStatusCode.OK;
                response.Content = new StringContent(JsonConvert.SerializeObject(appSettings));
                return response;
            }
            catch (Exception ex)
            {
                response.StatusCode = HttpStatusCode.InternalServerError;
                response.Content = new StringContent("Sorry, some error occurred. We will notify you once this gets resolved.");
                return response;
                //log this exception in event log collection to evaluate why this error occurred
            }
        }

        public HttpResponseMessage Get(string applicationName)
        {
            HttpResponseMessage response = Request.CreateResponse();
            try
            {
                dynamic appSettings = ApplicationSettings.GetApplicationSettings(applicationName);

                response.StatusCode = HttpStatusCode.OK;
                response.Content = new StringContent(JsonConvert.SerializeObject(appSettings));
                return response;
            }
            catch (Exception ex)
            {
                response.StatusCode = HttpStatusCode.InternalServerError;
                response.Content = new StringContent("Sorry, some error occurred. We will notify you once this gets resolved.");
                return response;
                //log this exception in event log collection to evaluate why this error occurred
            }
        }

        // POST: api/AppSettings
        public void Post([FromBody]string value)
        {
        }

        // PUT: api/AppSettings/5
        public void Put(int id, [FromBody]string value)
        {
        }

        // DELETE: api/AppSettings/5
        public void Delete(int id)
        {
        }
    }
}