From a3a3d504de15d615bbc30d6068e79f88c97ef5d5 Mon Sep 17 00:00:00 2001 From: gagan.deep Date: Thu, 22 Mar 2018 12:06:40 +0530 Subject: [PATCH] merge harpreet code --- 400-SOURCECODE/AIAHTML5.ADMIN.API/Controllers/UserGroupController.cs | 16 +++++++++------- 400-SOURCECODE/AIAHTML5.ADMIN.API/Entity/AIADBEntity.Context.cs | 37 +++++++++++++++++++++++++++++++++++-- 400-SOURCECODE/AIAHTML5.ADMIN.API/Entity/AIADBEntity.edmx | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 500-DBDump/AIA-StoredProcedures/usp_GetLicenseUserGroupUsers.sql | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 500-DBDump/AIA-StoredProcedures/usp_UpdateLicenseUserGroupUsers.sql | 28 +++++++++++++++++++++------- 5 files changed, 215 insertions(+), 17 deletions(-) create mode 100644 500-DBDump/AIA-StoredProcedures/usp_GetLicenseUserGroupUsers.sql diff --git a/400-SOURCECODE/AIAHTML5.ADMIN.API/Controllers/UserGroupController.cs b/400-SOURCECODE/AIAHTML5.ADMIN.API/Controllers/UserGroupController.cs index 593240a..f4c3718 100644 --- a/400-SOURCECODE/AIAHTML5.ADMIN.API/Controllers/UserGroupController.cs +++ b/400-SOURCECODE/AIAHTML5.ADMIN.API/Controllers/UserGroupController.cs @@ -24,13 +24,14 @@ namespace AIAHTML5.ADMIN.API.Controllers [Route("LicenseUserGroups")] [HttpGet] - public HttpResponseMessage GetLicenseUserGroups(int LicenseId) + public HttpResponseMessage GetLicenseUserGroups(int LicenseId, int pageNo, int pageLength) { List UserGroupList = new List(); + int recordCount = 0; try { - UserGroupList = UserGroupModel.GetLicenseUserGroups(dbContext, LicenseId); - return Request.CreateResponse(HttpStatusCode.OK, UserGroupList); + UserGroupList = UserGroupModel.GetLicenseUserGroups(dbContext, LicenseId, pageNo, pageLength, out recordCount); + return Request.CreateResponse(HttpStatusCode.OK, new { UserGroupList = UserGroupList, RecordCount = recordCount }); } catch (Exception ex) { @@ -41,13 +42,14 @@ namespace AIAHTML5.ADMIN.API.Controllers [Route("LicenseUserGroupUsers")] [HttpGet] - public HttpResponseMessage GetLicenseUserGroupUsers(int LicenseId, int UserGroupId) + 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); - return Request.CreateResponse(HttpStatusCode.OK, UserList); + UserList = UserGroupModel.GetLicenseUserGroupUsers(dbContext, LicenseId, UserGroupId, AllUsers, pageNo, pageLength, out recordCount); + return Request.CreateResponse(HttpStatusCode.OK, new { UserList = UserList, RecordCount = recordCount }); } catch (Exception ex) { @@ -67,7 +69,7 @@ namespace AIAHTML5.ADMIN.API.Controllers UserGroupEntity.Title = jsonData["title"].Value(); UserGroupEntity.IsActive = jsonData["isActive"].Value(); UserGroupEntity.CreationDate = jsonData["creationDate"].Value(); - UserGroupEntity.ModifiedDate = jsonData["modifiedDate"].Value(); + UserGroupEntity.ModifiedDate = jsonData["modifiedDate"].Value(); try { Status = UserGroupModel.InsertUpdateLicenseUserGroup(dbContext, UserGroupEntity); diff --git a/400-SOURCECODE/AIAHTML5.ADMIN.API/Entity/AIADBEntity.Context.cs b/400-SOURCECODE/AIAHTML5.ADMIN.API/Entity/AIADBEntity.Context.cs index 228e18b..5f5cba6 100644 --- a/400-SOURCECODE/AIAHTML5.ADMIN.API/Entity/AIADBEntity.Context.cs +++ b/400-SOURCECODE/AIAHTML5.ADMIN.API/Entity/AIADBEntity.Context.cs @@ -3479,13 +3479,21 @@ namespace AIAHTML5.ADMIN.API.Entity return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("usp_DeleteLicenseUserGroup", userGroupIdParameter, status); } - public virtual ObjectResult usp_GetLicenseUserGroups(Nullable licenseId) + public virtual ObjectResult usp_GetLicenseUserGroups(Nullable licenseId, Nullable pageNo, Nullable pageLength, ObjectParameter recordCount) { var licenseIdParameter = licenseId.HasValue ? new ObjectParameter("LicenseId", licenseId) : new ObjectParameter("LicenseId", typeof(int)); - return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("usp_GetLicenseUserGroups", licenseIdParameter); + var pageNoParameter = pageNo.HasValue ? + new ObjectParameter("pageNo", pageNo) : + new ObjectParameter("pageNo", typeof(int)); + + var pageLengthParameter = pageLength.HasValue ? + new ObjectParameter("pageLength", pageLength) : + new ObjectParameter("pageLength", typeof(int)); + + return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("usp_GetLicenseUserGroups", licenseIdParameter, pageNoParameter, pageLengthParameter, recordCount); } public virtual int usp_InsertUpdateLicenseUserGroup(Nullable id, Nullable licenseId, string title, Nullable creationDate, Nullable modifiedDate, Nullable isActive, ObjectParameter status) @@ -3734,5 +3742,30 @@ namespace AIAHTML5.ADMIN.API.Entity return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("usp_CheckAccountNoExists", accountNoParameter, status); } + + public virtual ObjectResult usp_GetLicenseUserGroupUsers(Nullable licenseId, Nullable groupId, Nullable allUsers, Nullable pageNo, Nullable pageLength, ObjectParameter recordCount) + { + var licenseIdParameter = licenseId.HasValue ? + new ObjectParameter("licenseId", licenseId) : + new ObjectParameter("licenseId", typeof(int)); + + var groupIdParameter = groupId.HasValue ? + new ObjectParameter("groupId", groupId) : + new ObjectParameter("groupId", typeof(int)); + + var allUsersParameter = allUsers.HasValue ? + new ObjectParameter("allUsers", allUsers) : + new ObjectParameter("allUsers", typeof(bool)); + + var pageNoParameter = pageNo.HasValue ? + new ObjectParameter("pageNo", pageNo) : + new ObjectParameter("pageNo", typeof(int)); + + var pageLengthParameter = pageLength.HasValue ? + new ObjectParameter("pageLength", pageLength) : + new ObjectParameter("pageLength", typeof(int)); + + return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("usp_GetLicenseUserGroupUsers", licenseIdParameter, groupIdParameter, allUsersParameter, pageNoParameter, pageLengthParameter, recordCount); + } } } diff --git a/400-SOURCECODE/AIAHTML5.ADMIN.API/Entity/AIADBEntity.edmx b/400-SOURCECODE/AIAHTML5.ADMIN.API/Entity/AIADBEntity.edmx index 9ea5f41..4baa8ba 100644 --- a/400-SOURCECODE/AIAHTML5.ADMIN.API/Entity/AIADBEntity.edmx +++ b/400-SOURCECODE/AIAHTML5.ADMIN.API/Entity/AIADBEntity.edmx @@ -2694,6 +2694,17 @@ warning 6002: The table/view 'AIADatabaseV5.dbo.VocabTermNumberToSystemMap' does + + + + + + + + + + + @@ -6451,7 +6462,10 @@ FROM [dbo].[VocabTermNumberToSystemMap] AS [VocabTermNumberToSystemMap] - + + + + @@ -6527,6 +6541,14 @@ FROM [dbo].[VocabTermNumberToSystemMap] AS [VocabTermNumberToSystemMap] + + + + + + + + @@ -7530,6 +7552,16 @@ FROM [dbo].[VocabTermNumberToSystemMap] AS [VocabTermNumberToSystemMap] + + + + + + + + + + @@ -10057,6 +10089,20 @@ FROM [dbo].[VocabTermNumberToSystemMap] AS [VocabTermNumberToSystemMap] + + + + + + + + + + + + + + diff --git a/500-DBDump/AIA-StoredProcedures/usp_GetLicenseUserGroupUsers.sql b/500-DBDump/AIA-StoredProcedures/usp_GetLicenseUserGroupUsers.sql new file mode 100644 index 0000000..c2ef3dd --- /dev/null +++ b/500-DBDump/AIA-StoredProcedures/usp_GetLicenseUserGroupUsers.sql @@ -0,0 +1,103 @@ +SET QUOTED_IDENTIFIER ON +GO +SET ANSI_NULLS ON +GO + +if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_GetLicenseUserGroupUsers]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) +drop procedure [dbo].[usp_GetLicenseUserGroupUsers] +GO + +-- ==================================================== +-- Author: Magic Software +-- Create date: 20-Mar-2018 +-- Description: To get all user group users with all users of a license +-- ==================================================== +create PROCEDURE [dbo].[usp_GetLicenseUserGroupUsers] + -- Add the parameters for the stored procedure here + @licenseId int, @groupId int, @allUsers bit, @pageNo int, @pageLength int, @recordCount int out +AS +BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + + if (@AllUsers = 1) + begin + --Get the records on the basis of parameters page length and page number rows + select * from + (SELECT row_number() OVER (order by AIAUser.Id) AS RowNo, AIAUser.Id, AIAUser.FirstName, AIAUser.LastName, AIAUser.LoginId, + AIAUser.EmailId, Edition.Title, + (CASE WHEN UserGroupToAIAUser.UserId IS NULL THEN 0 ELSE 1 END) AS InGroup + FROM + AIAUser + INNER JOIN AIAUserToLicenseEdition ON AIAUser.Id = AIAUserToLicenseEdition.UserId + INNER JOIN LicenseToEdition ON AIAUserToLicenseEdition.LicenseEditionId = LicenseToEdition.Id + INNER JOIN Edition ON Edition.Id = LicenseToEdition.EditionId + INNER JOIN License ON LicenseToEdition.LicenseId = License.Id AND License.IsActive = 1 + LEFT JOIN UserGroupToAIAUser ON UserGroupToAIAUser.UserId = AIAUser.Id + AND UserGroupToAIAUser.UserGroupId = @groupId + WHERE License.Id = @licenseId AND AIAUser.UserTypeId = 6 + ) TB + WHERE RowNo > @pageLength * (@pageNo - 1) and RowNo <= @pageLength * @pageNo; + + --Calculate total number of records + select @recordCount = count(ResultTable.Id) from ( + SELECT AIAUser.Id, AIAUser.FirstName, AIAUser.LastName, AIAUser.LoginId, + AIAUser.EmailId, Edition.Title, + (CASE WHEN UserGroupToAIAUser.UserId IS NULL THEN 0 ELSE 1 END) AS InGroup + FROM + AIAUser + INNER JOIN AIAUserToLicenseEdition ON AIAUser.Id = AIAUserToLicenseEdition.UserId + INNER JOIN LicenseToEdition ON AIAUserToLicenseEdition.LicenseEditionId = LicenseToEdition.Id + INNER JOIN Edition ON Edition.Id = LicenseToEdition.EditionId + INNER JOIN License ON LicenseToEdition.LicenseId = License.Id AND License.IsActive = 1 + LEFT JOIN UserGroupToAIAUser ON UserGroupToAIAUser.UserId = AIAUser.Id + AND UserGroupToAIAUser.UserGroupId = @groupId + WHERE License.Id = @licenseId AND AIAUser.UserTypeId = 6) as ResultTable; + end + else + begin + --Get the records on the basis of parameters page length and page number rows + select * from + (SELECT row_number() OVER (order by AIAUser.Id) AS RowNo, AIAUser.Id, AIAUser.FirstName, AIAUser.LastName, AIAUser.LoginId, + AIAUser.EmailId, Edition.Title, + (CASE WHEN UserGroupToAIAUser.UserId IS NULL THEN 0 ELSE 1 END) AS InGroup + FROM + AIAUser + INNER JOIN AIAUserToLicenseEdition ON AIAUser.Id = AIAUserToLicenseEdition.UserId + INNER JOIN LicenseToEdition ON AIAUserToLicenseEdition.LicenseEditionId = LicenseToEdition.Id + INNER JOIN Edition ON Edition.Id = LicenseToEdition.EditionId + INNER JOIN License ON LicenseToEdition.LicenseId = License.Id AND License.IsActive = 1 + LEFT JOIN UserGroupToAIAUser ON UserGroupToAIAUser.UserId = AIAUser.Id + AND UserGroupToAIAUser.UserGroupId = @groupId + WHERE License.Id = @licenseId AND AIAUser.UserTypeId = 6 and UserGroupToAIAUser.UserId > 0 + ) TB + WHERE RowNo > @pageLength * (@pageNo - 1) and RowNo <= @pageLength * @pageNo; + + --Calculate total number of records + select @recordCount = count(ResultTable.Id) from ( + SELECT AIAUser.Id, AIAUser.FirstName, AIAUser.LastName, AIAUser.LoginId, + AIAUser.EmailId, Edition.Title, + (CASE WHEN UserGroupToAIAUser.UserId IS NULL THEN 0 ELSE 1 END) AS InGroup + FROM + AIAUser + INNER JOIN AIAUserToLicenseEdition ON AIAUser.Id = AIAUserToLicenseEdition.UserId + INNER JOIN LicenseToEdition ON AIAUserToLicenseEdition.LicenseEditionId = LicenseToEdition.Id + INNER JOIN Edition ON Edition.Id = LicenseToEdition.EditionId + INNER JOIN License ON LicenseToEdition.LicenseId = License.Id AND License.IsActive = 1 + LEFT JOIN UserGroupToAIAUser ON UserGroupToAIAUser.UserId = AIAUser.Id + AND UserGroupToAIAUser.UserGroupId = @groupId + WHERE License.Id = @licenseId AND AIAUser.UserTypeId = 6 and UserGroupToAIAUser.UserId > 0) as ResultTable; + end + +END + +GO +SET QUOTED_IDENTIFIER OFF +GO +SET ANSI_NULLS ON +GO + + + + diff --git a/500-DBDump/AIA-StoredProcedures/usp_UpdateLicenseUserGroupUsers.sql b/500-DBDump/AIA-StoredProcedures/usp_UpdateLicenseUserGroupUsers.sql index 8797db8..b223af3 100644 --- a/500-DBDump/AIA-StoredProcedures/usp_UpdateLicenseUserGroupUsers.sql +++ b/500-DBDump/AIA-StoredProcedures/usp_UpdateLicenseUserGroupUsers.sql @@ -21,7 +21,7 @@ SET NOCOUNT ON; DECLARE @pos INT, @tempUserId int; DECLARE @len INT; -DECLARE @value varchar(10); +DECLARE @value varchar(10), @value1 varchar(10); if(@UserIds != '') begin @@ -32,17 +32,31 @@ end BEGIN TRY BEGIN TRANSACTION - delete UGU from UserGroupToAIAUser UGU where UserGroupId = @UserGroupId; - set @pos = 0 + set @pos = 1 set @len = 0 - WHILE CHARINDEX(',', @UserIds, @pos+1)>0 + WHILE CHARINDEX(',', @UserIds, @pos)>0 BEGIN - set @len = CHARINDEX(',', @UserIds, @pos+1) - @pos; - set @value = SUBSTRING(@UserIds, @pos, @len); + set @len = CHARINDEX(',', @UserIds, @pos) - @pos; + set @value = SUBSTRING(@UserIds, @pos, CHARINDEX('-', @UserIds, @pos) - @pos); + set @value1 = SUBSTRING(@UserIds, CHARINDEX('-', @UserIds, @pos) + 1, @len - len(@value) - 1); + select @pos, @len, @value, @value1; set @tempUserId = convert(int, @value); - insert into UserGroupToAIAUser(UserGroupId, UserId) values(@UserGroupId, @tempUserId); + if(exists(select * from UserGroupToAIAUser where UserGroupId = @UserGroupId and UserId = @tempUserId)) + begin + if(@value1 = '0') + begin + delete from UserGroupToAIAUser where UserGroupId = @UserGroupId and UserId = @tempUserId; + end + end + else + begin + if(@value1 = '1') + begin + insert into UserGroupToAIAUser(UserGroupId, UserId) values(@UserGroupId, @tempUserId); + end + end set @pos = CHARINDEX(',', @UserIds, @pos+@len) + 1; END -- libgit2 0.21.4