using System; using System.Collections.Generic; using System.Linq; using System.Web; using AIAHTML5.ADMIN.API.Entity; namespace AIAHTML5.ADMIN.API.Models { public class UserModel { public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string EmailId { get; set; } public string LoginId { get; set; } public string NewLoginId { get; set; } public string Password { get; set; } public int SecurityQuestionId { get; set; } public string SecurityAnswer { get; set; } public int CreatorId { get; set; } public DateTime CreationDate { get; set; } public DateTime DeactivationDate { get; set; } public int ModifierId { get; set; } public DateTime ModifiedDate { get; set; } public int UserTypeId { get; set; } public bool IsActive { get; set; } public int LicenseId { get; set; } public int EditionId { get; set; } public short iUserTypeId { get; set; } public int InGroup { get; set; } public string ProductEdition { get; set; } public string Createdby { get; set; } public string Modifiedby { get; set; } public static bool UpdateUserProfile(AIADatabaseV5Entities dbContext, int intUserID, string strFirstName, string strLastName, string strEmailID) { var spStatus = new System.Data.Objects.ObjectParameter("Status", 0); try { dbContext.usp_UpdateUserProfile(intUserID, strFirstName, strLastName, strEmailID, spStatus); if (spStatus.Value.ToString() == "1") { return true; } else { return false; } } catch (Exception ex) { return false; } } public static bool UpdateUserPassword(AIADatabaseV5Entities dbContext, int intUserID, string newPassword) { var spStatus = new System.Data.Objects.ObjectParameter("Status", 0); try { dbContext.usp_UpdateAiaUserPassword(intUserID, newPassword, spStatus); return (bool)spStatus.Value; } catch (Exception ex) { return false; } } public static string UpdateUserId(AIADatabaseV5Entities dbContext, int id, string userId, string oldUserId) { var spStatus = new System.Data.Objects.ObjectParameter("Status", 0); try { dbContext.usp_UpdateUserId(id, userId, oldUserId, spStatus); if (spStatus.Value.ToString() == "1") { // return "success"; return "1"; } else if (spStatus.Value.ToString() == "2") { return "2"; // return "Already Exist Userid"; } else { return "fail"; } } catch (Exception ex) { return ex.Message; } } public static string InsertUser(AIADatabaseV5Entities dbContext,UserModel UserEntity) { var spStatus = new System.Data.Objects.ObjectParameter("Status", 0); short questionId = 0; short EditionId=(short) UserEntity.EditionId; try { dbContext.usp_InsertAIAUser(UserEntity.LoginId, UserEntity.Password, UserEntity.FirstName, UserEntity.LastName, (byte)UserEntity.iUserTypeId, UserEntity.EmailId, (byte)questionId, null, UserEntity.Id, UserEntity.LicenseId, (byte)EditionId, spStatus); return spStatus.Value.ToString(); } catch(Exception ex) { return ex.Message; } } public static string UpdateUser(AIADatabaseV5Entities dbContext, UserModel UserEntity) { var spStatus = new System.Data.Objects.ObjectParameter("Status", 0); short questionId = 0; short EditionId = (short)UserEntity.EditionId; try { dbContext.usp_UpdateAIAUser(UserEntity.LoginId, UserEntity.Password, UserEntity.FirstName, UserEntity.LastName,UserEntity.EmailId,UserEntity.Id,UserEntity.CreatorId,(UserEntity.IsActive ? (byte)1 :(byte)0),spStatus); return spStatus.Value.ToString(); } catch (Exception ex) { return ex.Message; } } public static bool UpdateUnblockedUser(AIADatabaseV5Entities dbContext, List ids) { var spStatus = new System.Data.Objects.ObjectParameter("Status", 0); try { foreach (var item in ids) { dbContext.usp_UpdateblockedUser(item, spStatus); if (spStatus.Value.ToString()!="1") break; } return (spStatus.Value.ToString()=="1"?true:false); } catch (Exception ex) { return false; } } public static bool InsertDeleteUserManageRight(AIADatabaseV5Entities dbContext, List SelectectedUserRights, List UncheckedUserRights, int UserId,string RoleName) { var spStatus = new System.Data.Objects.ObjectParameter("Status", 0); try { foreach (var item in SelectectedUserRights) { dbContext.usp_InsertDeleteUserManageRights(RoleName,item,UserId,"Insert", spStatus); if (!(bool)spStatus.Value) break; } foreach (var item in UncheckedUserRights) { dbContext.usp_InsertDeleteUserManageRights(RoleName, item, UserId, "Remove", spStatus); if (!(bool)spStatus.Value) break; } return (bool)spStatus.Value; } catch (Exception ex) { return false; } } } }