UserGroupModel.cs 4.16 KB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using AIAHTML5.ADMIN.API.Entity;

namespace AIAHTML5.ADMIN.API.Models
{
    public class UserGroupModel
    {
        public int Id { get; set; }
        public int LicenseId { get; set; }
        public string Title { get; set; }
        public DateTime? CreationDate { get; set; }
        public DateTime? ModifiedDate { get; set; }
        public bool? IsActive { get; set; }
        public int? TotalUsers { get; set; }

        public static List<UserGroupModel> GetLicenseUserGroups(AIADatabaseV5Entities dbContext, int LicenseId)
        {
            List<UserGroupModel> UserGroupList = new List<UserGroupModel>();
            UserGroupModel UserGroupObj = new UserGroupModel();
            try
            {
                var result = dbContext.usp_GetLicenseUserGroups(LicenseId).ToList();
                foreach (var item in result)
                {
                    UserGroupObj = new UserGroupModel();
                    UserGroupObj.Id = item.Id;
                    UserGroupObj.LicenseId = item.LicenseId;
                    UserGroupObj.Title = item.Title;
                    UserGroupObj.IsActive = item.IsActive;
                    UserGroupObj.ModifiedDate = item.ModifiedDate;
                    UserGroupObj.CreationDate = item.CreationDate;
                    UserGroupObj.TotalUsers = item.TotalUsers;
                    UserGroupList.Add(UserGroupObj);
                }
            }
            catch (Exception ex) { }
            return UserGroupList;
        }

        public static List<UserModel> GetLicenseUserGroupUsers(AIADatabaseV5Entities dbContext, int LicenseId, int UserGroupId)
        {
            List<UserModel> UserList = new List<UserModel>();
            UserModel UserModelObj = new UserModel();
            try
            {
                var result = dbContext.GetAllUserWithGroup(LicenseId, UserGroupId).ToList();
                foreach (var item in result)
                {
                    UserModelObj = new UserModel();
                    UserModelObj.Id = item.Id;
                    UserModelObj.FirstName = item.FirstName;
                    UserModelObj.LastName = item.LastName;
                    UserModelObj.LoginId = item.LoginId;
                    UserModelObj.EmailId = item.EmailId;
                    UserModelObj.ProductEdition = item.Title;
                    UserModelObj.InGroup = item.InGroup;
                    UserList.Add(UserModelObj);
                }
            }
            catch (Exception ex) { }
            return UserList;
        }

        public static bool InsertUpdateLicenseUserGroup(AIADatabaseV5Entities dbContext, UserGroupModel UserGroupEntity)
        {
            var spStatus = new System.Data.Objects.ObjectParameter("Status", 0);
            try
            {
                dbContext.usp_InsertUpdateLicenseUserGroup(UserGroupEntity.Id, UserGroupEntity.LicenseId, UserGroupEntity.Title, 
                    UserGroupEntity.CreationDate, UserGroupEntity.ModifiedDate, UserGroupEntity.IsActive, spStatus);
                return (bool)spStatus.Value;
            }
            catch (Exception ex)
            {
                return false;
            }
        }

        public static bool UpdateLicenseUserGroupUsers(AIADatabaseV5Entities dbContext, int UserGroupId, string UserIds)
        {
            var spStatus = new System.Data.Objects.ObjectParameter("Status", 0);
            try
            {
                dbContext.usp_UpdateLicenseUserGroupUsers(UserGroupId, UserIds, spStatus);
                return (bool)spStatus.Value;
            }
            catch (Exception ex)
            {
                return false;
            }
        }

        public static bool DeleteLicenseUserGroup(AIADatabaseV5Entities dbContext, int UserGroupId)
        {
            var spStatus = new System.Data.Objects.ObjectParameter("Status", 0);
            try
            {
                dbContext.usp_DeleteLicenseUserGroup(UserGroupId, spStatus);
                return (bool)spStatus.Value;
            }
            catch (Exception ex)
            {
                return false;
            }
        }

    }

}