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("UserGroup")] public class UserGroupController : ApiController { AIADatabaseV5Entities dbContext = new AIADatabaseV5Entities(); [Route("LicenseUserGroups")] [HttpGet] public HttpResponseMessage GetLicenseUserGroups(int LicenseId, int pageNo, int pageLength) { List UserGroupList = new List(); int recordCount = 0; try { UserGroupList = UserGroupModel.GetLicenseUserGroups(dbContext, LicenseId, pageNo, pageLength, out recordCount); return Request.CreateResponse(HttpStatusCode.OK, new { UserGroupList = UserGroupList, RecordCount = recordCount }); } catch (Exception ex) { // Log exception code goes here return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message); } } [Route("LicenseUserGroupUsers")] [HttpGet] public HttpResponseMessage GetLicenseUserGroupUsers(int LicenseId, int UserGroupId, bool AllUsers, int pageNo, int pageLength) { List UserList = new List(); int recordCount = 0; try { UserList = UserGroupModel.GetLicenseUserGroupUsers(dbContext, LicenseId, UserGroupId, AllUsers, pageNo, pageLength, out recordCount); return Request.CreateResponse(HttpStatusCode.OK, new { UserList = UserList, RecordCount = recordCount }); } catch (Exception ex) { // Log exception code goes here return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message); } } [Route("InsertUpdateLicenseUserGroup")] [HttpPost] public HttpResponseMessage InsertUpdateLicenseUserGroup(JObject jsonData) { bool Status = false; UserGroupModel UserGroupEntity = new UserGroupModel(); UserGroupEntity.Id = jsonData["id"].Value(); UserGroupEntity.LicenseId = jsonData["licenseId"].Value(); UserGroupEntity.Title = jsonData["title"].Value(); UserGroupEntity.IsActive = jsonData["isActive"].Value(); UserGroupEntity.CreationDate = jsonData["creationDate"].Value(); UserGroupEntity.ModifiedDate = jsonData["modifiedDate"].Value(); try { Status = UserGroupModel.InsertUpdateLicenseUserGroup(dbContext, UserGroupEntity); 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("UpdateLicenseUserGroupUsers")] [HttpPost] public HttpResponseMessage UpdateLicenseUserGroupUsers(JObject jsonData) { bool Status = false; int UserGroupId = jsonData["userGroupId"].Value(); string UserIds = jsonData["userIds"].Value(); try { Status = UserGroupModel.UpdateLicenseUserGroupUsers(dbContext, UserGroupId, UserIds); 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("DeleteLicenseUserGroup")] [HttpGet] public HttpResponseMessage DeleteLicenseUserGroup(int UserGroupId) { bool Status = false; try { Status = UserGroupModel.DeleteLicenseUserGroup(dbContext, UserGroupId); 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("CheckDuplicateLicenseUserGroup")] [HttpGet] public HttpResponseMessage CheckDuplicateLicenseUserGroup(int LicenseId, string Title) { bool Status = false; try { Status = UserGroupModel.CheckDuplicateLicenseUserGroup(dbContext, LicenseId, Title); return Request.CreateResponse(HttpStatusCode.OK, Status.ToString()); } catch (Exception ex) { // Log exception code goes here return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message); } } } }