ChangeUserIDController.cs 1.83 KB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using AIAHTML5.Server.Models;
using System.Web.Http.Cors;
using System.Web.Cors;
using AIAHTML5.Server.Constants;
using log4net;

namespace AIAHTML5.Server.Controllers
{
    [EnableCors(origins: "http://localhost:92", headers: "*", methods: "*")]
    public class ChangeUserIDController : ApiController
    {
        DbModel objDbModel = new DbModel();
        // GET: api/ChangeUserID
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }

        // GET: api/ChangeUserID/5
        public HttpResponseMessage Get(int iUserId, string sLoginId) //IEnumerable<string>
        {
            string userDetails = objDbModel.GetUserInfoByIDandLoginId(iUserId, sLoginId);

            var userJson = JsonConvert.SerializeObject(userDetails, Formatting.Indented);

            return Request.CreateResponse(HttpStatusCode.OK, userJson);
        }

        // POST: api/ChangeUserID
        public string Post([FromBody]JObject userInfo)
        {
            ILog logger = log4net.LogManager.GetLogger((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
            int iUserId = Convert.ToInt32(userInfo["iUserId"]);
            string sLodinId = userInfo["newLoginId"].ToString();

            int result = objDbModel.UpdateUserID(iUserId, sLodinId);

            if (result > 0)
                return AdminConstant.SUCCESS;
            else
                return AdminConstant.FAILED;
        }

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

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