UserController.cs
5.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
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.ADMIN.API.Models;
using System.Web.Http.Cors;
using System.Web.Cors;
using AIAHTML5.Server.Constants;
using log4net;
using System.Text;
using AIAHTML5.ADMIN.API.Entity;
namespace AIAHTML5.ADMIN.API.Controllers
{
[EnableCors(origins: "http://localhost:4200", headers: "*", methods: "*")]
[RoutePrefix("User")]
public class UserController : ApiController
{
AIADatabaseV5Entities dbContext = new AIADatabaseV5Entities();
[Route("Api/GetUserProfile/{userId}")]
[HttpGet]
public IHttpActionResult GetUserProfile(int userId)
{
dbContext.Configuration.ProxyCreationEnabled = false;
try
{
return Ok(dbContext.AIAUsers.Where(u => u.Id == userId).ToList());
}
catch (Exception ex)
{
throw ex;
}
//return ToJson(dbContext.AIAUsers.Where(u => u.Id == userId).AsEnumerable());
}
[Route("Api/UpdateProfile")]
[HttpPost]
public HttpResponseMessage UpdateUserProfile(UserModel userInfo)
{
bool Status = false;
try
{
Status = UserModel.UpdateUserProfile(dbContext, userInfo.Id, userInfo.FirstName, userInfo.LastName, userInfo.EmailId);
if (Status)
{
return Request.CreateResponse(HttpStatusCode.OK, Status.ToString());
}
else
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, Status.ToString());
}
}
catch (Exception ex)
{
// Log exception code goes here
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message);
}
}
[Route("Api/ChangeUserPassword")]
[HttpPost]
public HttpResponseMessage UpdateUserPassword(JObject jsonData)
{
bool Status = false;
int id = jsonData["id"].Value<Int32>();
string newPassword = jsonData["newPassword"].Value<string>();
try
{
Status = UserModel.UpdateUserPassword(dbContext, id, newPassword);
if (Status)
{
return Request.CreateResponse(HttpStatusCode.OK, Status.ToString());
}
else
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, Status.ToString());
}
}
catch (Exception ex)
{
// Log exception code goes here
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message);
}
}
[Route("Api/UpdateUserId")]
[HttpPost]
public HttpResponseMessage UpdateUserId(UserModel userInfo)
{
string Status = string.Empty;
try
{
Status = UserModel.UpdateUserId(dbContext, userInfo.Id, userInfo.NewLoginId, userInfo.LoginId);
if (Status.Equals("1"))
{
return Request.CreateResponse(HttpStatusCode.OK, "success");
}
else if (Status.Equals("2"))
{
return Request.CreateResponse(HttpStatusCode.OK, "Already Exist Userid");
}
else
{
return Request.CreateResponse(HttpStatusCode.BadRequest, "Please try again some time later.");
}
}
catch (Exception ex)
{
// Log exception code goes here
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message);
}
}
#region USERS
[Route("Api/GetUserType/{UserTypeId}")]
[HttpGet]
public IHttpActionResult GetUserType(int UserTypeId)
{
dbContext.Configuration.ProxyCreationEnabled = false;
List<UserType> userTypelist = new List<UserType>();
var userTypeEntity = dbContext.usp_GetUserType(UserTypeId).ToList();
userTypelist = userTypeEntity.Select(l => new UserType() { Id = l.Id, Title = l.Title }).ToList();
//userTypelist.Insert(0, new UserType { Id = 0, Title = "All" });
return Ok(userTypelist);
}
[Route("Api/GetAccountType/{AccountTypeId}")]
[HttpGet]
public IHttpActionResult GetAccountType(int AccountTypeId)
{
dbContext.Configuration.ProxyCreationEnabled = false;
return Ok(AccountTypeModel.GetAccountTypeList(dbContext, AccountTypeId));
}
[Route("Api/Users")]
[HttpGet]
public IHttpActionResult UserList(string firstname, string lastname, string emailid, string accountnumber, string usertypeid, string accounttypeid)
{
int UserTypeId = (!string.IsNullOrEmpty(usertypeid) ? Convert.ToInt32(usertypeid) : 0);
int AccountTypeId = (!string.IsNullOrEmpty(accounttypeid) ? Convert.ToInt32(accounttypeid) : 0);
dbContext.Configuration.ProxyCreationEnabled = false;
List<GetSearchUserList_Result> Users = dbContext.GetSearchUserList(firstname, lastname, emailid, accountnumber, UserTypeId, AccountTypeId, 1).ToList();
return Ok(Users);
}
#endregion
protected HttpResponseMessage ToJson(dynamic obj)
{
var response = Request.CreateResponse(HttpStatusCode.OK);
response.Content = new StringContent(JsonConvert.SerializeObject(obj), Encoding.UTF8, "application/jsonP");
return response;
}
}
}