protected void MakeAdmin(object sender, EventArgs e) { try { bool success = false; foreach (GridViewRow AdminRow in gvAdmins.Rows) { CheckBox isAdminchk = AdminRow.FindControl("chkAdmin") as CheckBox; if (isAdminchk.Checked) { Label AdminUserID = AdminRow.FindControl("UserID") as Label; Label lblRollNo = AdminRow.FindControl("lblRollNo") as Label; UserGroupMapping objUserGroupMapping = new UserGroupMapping(); objUserGroupMapping.UserGroupID = GroupID; objUserGroupMapping.UserID = AdminUserID.Text; objUserGroupMapping.isAdmin = true; objUserGroupMapping.SerialNoForGroup = lblRollNo.Text; new UserController().DeleteUserGroupMapping(AdminUserID.Text, GroupID); string strMsg = new UserController().CreateUserGroupMapping(objUserGroupMapping); success = true; } } if (success == true) { General.ShowAlertMessage("Admin Mapped successfully!"); bindGvContacts(); } } catch (Exception ex) { ErrorMessage.Text = ex.Message; } }
public IActionResult Update(UserGroupDTO userGroupDTO, int Id) { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrorMessage())); } else { IDataResult <UserGroup> result = _iUserGroupService.GetById(Id); if (result == null) { return(BadRequest(result.Message)); } else { _iMapper = UserGroupMapping.GetMapper().CreateMapper(); UserGroup userGroup = _iMapper.Map <UserGroupDTO, UserGroup>(userGroupDTO); IResult updateResult = _iUserGroupService.Update(userGroup); if (updateResult.Success) { return(Ok(updateResult.Message)); } return(BadRequest(updateResult.Message)); } } }
public async Task <IActionResult> UpdateAsync(UserGroupDTO userGroupDTO, int Id) { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrorMessage())); } else { IDataResult <UserGroup> dataResult = await _iUserGroupService.FindByIdAsync(Id); if (dataResult.Data == null) { return(BadRequest(dataResult.Message)); } _iMapper = UserGroupMapping.GetMapper().CreateMapper(); UserGroup userGroup = _iMapper.Map <UserGroupDTO, UserGroup>(userGroupDTO); IResult result = await _iUserGroupService.UpdateAsync(userGroup); if (result.Success) { return(Ok(result.Message)); } return(BadRequest(result.Message)); } }
public void appServer_NewSessionConnected(WebSocketSession session) { try { var GroupId = session.Path.Split(',')[1].Split(':')[1]; var UserId = session.Path.Split(',')[0].Split(':')[1]; using (LystenEntities db = new LystenEntities()) { int gid = Convert.ToInt32(GroupId); int uid = Convert.ToInt32(UserId); var obj = db.Groups.Where(x => x.Id == gid).FirstOrDefault(); if (obj.GroupTypeId == 1) { if (!db.Groups.Any(x => x.CreatorId == uid && x.Id == gid)) { if (!db.UserGroupMappings.Any(x => x.UserId == uid && x.GroupId == gid)) { UserGroupMapping ugm = new UserGroupMapping() { GroupId = gid, UserId = uid }; db.UserGroupMappings.Add(ugm); db.SaveChanges(); } } } WebSocketSessionDb webs = new WebSocketSessionDb(); if (db.WebSocketSessionDbs.Any(x => x.GroupID == gid && x.UserId == uid)) { webs = db.WebSocketSessionDbs.Where(x => x.GroupID == gid && x.UserId == uid).FirstOrDefault(); webs.GroupID = Convert.ToInt32(GroupId); webs.UserId = Convert.ToInt32(UserId); webs.SessionId = session.SessionID; db.Entry(webs).State = EntityState.Modified; db.SaveChanges(); } else { webs.GroupID = Convert.ToInt32(GroupId); webs.UserId = Convert.ToInt32(UserId); webs.SessionId = session.SessionID; db.WebSocketSessionDbs.Add(webs); db.SaveChanges(); } } } catch (Exception ex) { CommonServices.ErrorLogging(ex); } }
/// <summary> /// Method for updating an existing user /// </summary> /// <param name="id"></param> /// <param name="updatedUserAc"></param> /// <returns></returns> public async Task UpdateUserAsync(string id, UpdateUserAc updatedUserAc, ApplicationUser currentUser) { // Update user details ApplicationUser existingUser = _iMSDbContext.Users.First(x => x.Id.Equals(id)); existingUser.UpdatedBy = currentUser.Id; existingUser.UpdatedOn = DateTime.UtcNow; existingUser.Name = updatedUserAc.Name; await _userManager.UpdateAsync(existingUser); // Add user institute UserInstituteMapping existingUserInstituteMapping = await _iMSDbContext.UserInstituteMappings.FirstOrDefaultAsync(x => x.UserId == id && x.InstituteId == updatedUserAc.InstituteId); if (existingUserInstituteMapping == null) { UserInstituteMapping userInstituteMapping = new UserInstituteMapping { InstituteId = updatedUserAc.InstituteId, UserId = existingUser.Id, CreatedOn = DateTime.UtcNow }; _iMSDbContext.UserInstituteMappings.Add(userInstituteMapping); await _iMSDbContext.SaveChangesAsync(); } // Update user role, if updated List <UserGroupMapping> userRolesMappingsList = await _iMSDbContext.UserGroupMapping.Where(x => x.UserId.Equals(existingUser.Id)).ToListAsync(); _iMSDbContext.UserGroupMapping.RemoveRange(userRolesMappingsList); await _iMSDbContext.SaveChangesAsync(); foreach (int userGroupId in updatedUserAc.UserGroupIdList) { UserGroup userGroup = await _iMSDbContext.UserGroups.FirstOrDefaultAsync(x => x.Id == userGroupId); if (userGroup != null) { UserGroupMapping userRolesMapping = new UserGroupMapping { UserGroupId = userGroup.Id, UserId = existingUser.Id, CreatedOn = DateTime.UtcNow }; _iMSDbContext.UserGroupMapping.Add(userRolesMapping); await _iMSDbContext.SaveChangesAsync(); } } }
/// <summary> /// Method for adding a new user /// </summary> /// <param name="newUserAc"></param> /// <returns></returns> public async Task AddNewUserAsync(AddUserAc newUserAc, ApplicationUser currentUser) { // Add new user ApplicationUser newUser = new ApplicationUser { Name = newUserAc.Name, Email = newUserAc.Email, UserName = newUserAc.Email, CreatedOn = DateTime.UtcNow, CreatedBy = currentUser.Id }; await _userManager.CreateAsync(newUser, newUserAc.Password); // Add user institute UserInstituteMapping userInstituteMapping = new UserInstituteMapping { InstituteId = newUserAc.InstituteId, UserId = newUser.Id, CreatedOn = DateTime.UtcNow }; _iMSDbContext.UserInstituteMappings.Add(userInstituteMapping); await _iMSDbContext.SaveChangesAsync(); // Add user role foreach (int userGroupId in newUserAc.UserGroupIdList) { UserGroup userGroup = await _iMSDbContext.UserGroups.FirstOrDefaultAsync(x => x.Id == userGroupId); if (userGroup != null) { UserGroupMapping userRolesMapping = new UserGroupMapping { UserGroupId = userGroup.Id, UserId = newUser.Id, CreatedOn = DateTime.UtcNow }; _iMSDbContext.UserGroupMapping.Add(userRolesMapping); await _iMSDbContext.SaveChangesAsync(); } } // Send welcome mail to the created user if (newUserAc.Email != null) { await SendWelcomeMail(new WelcomeMailToUserAc { Name = newUserAc.Name, Password = newUserAc.Password }, newUserAc.Email, newUserAc.Name); } }
public IActionResult Add(UserGroupDTO UserGroupDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrorMessage())); } else { _iMapper = UserGroupMapping.GetMapper().CreateMapper(); UserGroup userGroup = _iMapper.Map <UserGroupDTO, UserGroup>(UserGroupDTO); IResult result = _iUserGroupService.Add(userGroup); if (result.Success) { return(Ok(result.Message)); } return(BadRequest(result.Message)); } }
public async Task <IActionResult> AddAsync(UserGroupDTO userGroupDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrorMessage())); } else { _iMapper = UserGroupMapping.GetMapper().CreateMapper(); UserGroup userGroup = _iMapper.Map <UserGroupDTO, UserGroup>(userGroupDTO); IResult result = await _iUserGroupService.AddAsync(userGroup); if (result.Success) { return(Ok(result.Message)); } return(BadRequest($"{result.Message} \n Try Again later can be either server error or user error ")); } }
public int CreateMapping(UserGroupMapping c) { try { SqlParameter[] m = new SqlParameter[5]; m[0] = new SqlParameter("@UserGroupID", c.UserGroupID); m[1] = new SqlParameter("@UserID", c.UserID); m[2] = new SqlParameter("@Group_MappingID", SqlDbType.Int); m[3] = new SqlParameter("@isAdmin", c.isAdmin); m[4] = new SqlParameter("@SerialNoForGroup", c.SerialNoForGroup); m[2].Direction = ParameterDirection.Output; SqlHelper.ExecuteNonQuery(Connection.Connection_string, CommandType.StoredProcedure, "UserGroupMapping_Insert", m); object ivalue = m[2].Value; return((int)ivalue); } catch (Exception ex) { throw ex; } }
protected void btnSaveGroup_Click(object sender, EventArgs e) { try { int cv = Convert.ToInt32(litClientID.Text); if (pnlGeoLocation.Visible == true && txtGeoLocation.Text == string.Empty) { General.ShowAlertMessage("Please enter geo location details"); txtGeoLocation.Focus(); } else if (pnlWifiID.Visible == true && txtWifiID.Text == string.Empty) { General.ShowAlertMessage("Please enter WIFI MAC ID"); txtWifiID.Focus(); } else { BusinessObjects.UserGroups cl = new BusinessObjects.UserGroups(); cl.Group_Name = txtGroupName.Text; cl.Description = txtDescription.Text; cl.ClientID = cv; cl.Owner = Context.User.Identity.Name; cl.FlowType = Convert.ToInt32(ddlFlowType.SelectedValue); cl.AttendanceOption = Convert.ToInt32(ddlSelfAttendanceOption.SelectedValue); cl.AttendanceOptionValue = string.Empty; cl.Department = txtDepartment.Text; cl.SubDepartment = txtSubDepartment.Text; cl.StartTime = TxtStartTime.Text; cl.EndTime = txtEndTime.Text; cl.GraceTime = Convert.ToInt32(txtGraceTime.Text); cl.NoOfClasses = txtNoOfClasses.Text; if (pnlGeoLocation.Visible == true) { cl.AttendanceOptionValue = txtGeoLocation.Text; } if (pnlWifiID.Visible == true) { cl.AttendanceOptionValue = txtWifiID.Text; } cl.CreateDate = DateTime.UtcNow.AddHours(5.5); cl.Image = string.Empty; cl.IsActive = true; cl.IsDeleted = false; cl.IsRole = false; cl.ModifiedDate = DateTime.UtcNow.AddHours(5.5); if (litGroupID.Text == string.Empty) { int GroupID = Convert.ToInt32(new UserController().CreateUserGroup(cl)); string userID = string.Empty; SqlParameter[] m = new SqlParameter[1]; m[0] = new SqlParameter("@ID", cv); SqlDataReader dr = SqlHelper.ExecuteReader(Connection.Connection_string, CommandType.StoredProcedure, "Client_Select", m); while (dr.Read()) { m = new SqlParameter[2]; m[0] = new SqlParameter("@ClientID", cv); m[1] = new SqlParameter("@Mobile", dr["MobileNo"].ToString()); try { userID = SqlHelper.ExecuteScalar(Connection.Connection_string, CommandType.StoredProcedure, "GetClientAdmin", m).ToString(); } catch { } } if (userID != string.Empty) { UserGroupMapping objUserGroupMapping = new UserGroupMapping(); objUserGroupMapping.UserGroupID = GroupID; objUserGroupMapping.UserID = userID; objUserGroupMapping.isAdmin = true; objUserGroupMapping.SerialNoForGroup = "0"; string strMsg = new UserController().CreateUserGroupMapping(objUserGroupMapping); } General.ShowAlertMessage("Group added successfully!"); } else { cl.UserGroupID = Convert.ToInt32(litGroupID.Text); new UserController().UpdateUserGroup(cl); string userID = string.Empty; SqlParameter[] m = new SqlParameter[1]; m[0] = new SqlParameter("@ID", cv); SqlDataReader dr = SqlHelper.ExecuteReader(Connection.Connection_string, CommandType.StoredProcedure, "Client_Select", m); while (dr.Read()) { m = new SqlParameter[2]; m[0] = new SqlParameter("@ClientID", cv); m[1] = new SqlParameter("@Mobile", dr["MobileNo"].ToString()); try { userID = SqlHelper.ExecuteScalar(Connection.Connection_string, CommandType.StoredProcedure, "GetClientAdmin", m).ToString(); } catch { } } if (userID != string.Empty) { UserGroupMapping objUserGroupMapping = new UserGroupMapping(); objUserGroupMapping.UserGroupID = cl.UserGroupID; objUserGroupMapping.UserID = userID; objUserGroupMapping.isAdmin = true; objUserGroupMapping.SerialNoForGroup = "0"; new UserController().DeleteUserGroupMapping(userID, cl.UserGroupID); string strMsg = new UserController().CreateUserGroupMapping(objUserGroupMapping); } General.ShowAlertMessage("Group updated successfully!"); } BindGroups(); txtGroupName.Text = string.Empty; txtDescription.Text = string.Empty; litGroupID.Text = string.Empty; ddlFlowType.Enabled = true; ddlSelfAttendanceOption.Enabled = true; } } catch (Exception ex) { General.ShowAlertMessage("Please validate the details and try again."); } }
protected void CreateGroup_Click(object sender, EventArgs e) { // General.SendSMS("9953624768", "this is test from ECHO"); try { // General.SendSMS("9953624768", "this is test from ECHO"); User currentUser = new UserController().GetUser(Context.User.Identity.Name); string img = string.Empty; if (fuImage.HasFile) { string filename = Guid.NewGuid().ToString(); string extn = Path.GetExtension(fuImage.PostedFile.FileName); fuImage.PostedFile.SaveAs(Server.MapPath("~/images/GroupImages/" + filename + extn)); img = filename + extn; } // string groupID = string.Empty; UserGroups group = new UserGroups { Group_Name = txtName.Text, Description = txtDesc.Text, Image = img, Owner = Context.User.Identity.Name, IsRole = false, IsDeleted = false, IsActive = true, CreateDate = DateTime.Now, ModifiedDate = DateTime.Now }; if (GroupID == 0) { GroupID = Convert.ToInt32(new UserController().CreateUserGroup(group)); UserGroupMapping objUserGroupMapping = new UserGroupMapping(); objUserGroupMapping.UserGroupID = GroupID; objUserGroupMapping.UserID = Context.User.Identity.Name; objUserGroupMapping.isAdmin = true; string strMsg = new UserController().CreateUserGroupMapping(objUserGroupMapping); } else { group.UserGroupID = GroupID; string ss = new UserController().UpdateUserGroup(group); } if (fuContacts.HasFile) { if (fuContacts.FileName.EndsWith(".xls") || fuContacts.FileName.EndsWith(".xlsx")) { fuContacts.PostedFile.SaveAs(Server.MapPath("~/ContactsUpload/" + GroupID + fuContacts.PostedFile.FileName)); string ContactsFile = Server.MapPath("~/ContactsUpload/" + GroupID + fuContacts.PostedFile.FileName); var ConnectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0; Data Source = {0}; Extended Properties =Excel 12.0;", ContactsFile); var adapter = new OleDbDataAdapter("select * from [Contacts$]", ConnectionString); var ds = new DataSet(); adapter.Fill(ds, "Contacts"); DataTable contacts = ds.Tables["Contacts"]; DataColumn dc = new DataColumn("Status", typeof(string)); contacts.Columns.Add(dc); gvContactsFromXls.DataSource = contacts; gvContactsFromXls.DataBind(); gvContacts.DataSource = null; gvContacts.DataBind(); int AdminCount = 0; foreach (GridViewRow row in gvContactsFromXls.Rows) { if (row.RowType == DataControlRowType.DataRow) { //if ((row.Cells[1].Text != string.Empty && row.Cells[1].Text != " ") || (row.Cells[2].Text != string.Empty && row.Cells[2].Text != " ")) //{ if (IsValidRow(row)) { // string strUserID = string.Empty; User u = null; if (row.Cells[3].Text.ToLower() == "yes") { if (row.Cells[1].Text != string.Empty && row.Cells[1].Text != " ") { u = new UserController().GetUserbyEmail(row.Cells[1].Text.Trim()); } if (u == null && row.Cells[2].Text != string.Empty && row.Cells[2].Text != " ") { u = new UserController().GetUserbyMobile(row.Cells[2].Text.Trim()); } } else { if (u == null && row.Cells[2].Text != string.Empty && row.Cells[2].Text != " ") { u = new UserController().GetUser_byNameAndMobile(row.Cells[2].Text.Trim(), row.Cells[0].Text); } } string strUserID = string.Empty; //User u = null; string couponCode = GenerateCoupon(); List <UserGroups> listGroup = new List <UserGroups>(); listGroup.Add(group); if (u == null) { User objUser = new User { CouponCode = couponCode, CreatedBy = Context.User.Identity.Name, CreateDate = DateTime.Now, DOB = Convert.ToDateTime("1/1/1900"), EMail = (row.Cells[1].Text == " ") ? string.Empty : row.Cells[1].Text, //row.Cells[1].Text?="": row.Cells[1].Text , FirstName = row.Cells[0].Text, IsDeleted = false, IsLockedOut = true, LastLockoutDate = DateTime.Now, LastLoginDate = DateTime.Now, LastName = string.Empty, LastPasswordChangedDate = DateTime.Now, MobileNo = row.Cells[2].Text, PWD = string.Empty, RoleID = 4, // UserGroup= listGroup,// for Normal user ImageID = string.Empty, Custom1 = row.Cells[4].Text, //used for Roll Number Custom2 = row.Cells[5].Text, //used for User Type(Gender or Teacher) Custom3 = row.Cells[6].Text, //used for Cast Custom4 = row.Cells[7].Text, //used for Physically Handicap Custom5 = "3", //This field is used Type of Flow that it should go Session = General.GetCurrentSession, ClientID = Convert.ToInt32(txtClientID.Text) }; if (row.Cells[3].Text.ToLower() == "yes") { objUser.IsLockedOut = false; } strUserID = new UserController().CreateUser(objUser); } else { strUserID = u.UserID; } bool isAdmin = false; UserGroupMapping objUserGroupMapping = new UserGroupMapping(); objUserGroupMapping.UserGroupID = GroupID; objUserGroupMapping.UserID = strUserID; objUserGroupMapping.isAdmin = isAdmin; IList <UserGroupMapping> mlist = new UserController().GetUserGroupMapping(strUserID); mlist = mlist.Where(ss => ss.UserGroupID == GroupID).ToList(); if (row.Cells[3].Text.ToLower() == "yes" && AdminCount <= 5) { isAdmin = true; AdminCount++; } if (mlist.Count < 1) { objUserGroupMapping.isAdmin = isAdmin; string strMsg = new UserController().CreateUserGroupMapping(objUserGroupMapping); } if (isAdmin) { if (u == null) { string encryptedCouponCode = Encryption.Encrypt(couponCode); if (encryptedCouponCode.Substring(encryptedCouponCode.Length - 2, 2) == "==") { encryptedCouponCode = encryptedCouponCode + "echo"; } encryptedCouponCode = encryptedCouponCode.Replace("+", "plus"); encryptedCouponCode = encryptedCouponCode.Replace(" ", "%20"); string messageBody = "Dear " + row.Cells[0].Text + ", Welcome to ECHO! You have been added to " + txtName.Text + " by" + currentUser.FirstName + " on EchoAttendance. Register using the following link: http://echocommunicator.com/account/register?cc=" + encryptedCouponCode + ". to download our mobile App click https://bit.ly/2RbXp5r"; string EmailBody = "Dear " + row.Cells[0].Text + ", <br/><br/>Welcome to ECHO!<br/><br/> You have been added to " + txtName.Text + " by" + currentUser.FirstName + " on EchoAttendance.<br/><br/> Register using the following link:http://echocommunicator.com/account/register?cc=" + encryptedCouponCode + " <br/><br/>to download our mobile App click https://bit.ly/2RbXp5r"; try { General.SendSMS(row.Cells[2].Text.Trim(), messageBody); General.SendEmail(row.Cells[1].Text.Trim(), "Welcome to ECHO", EmailBody); } catch { } row.Cells[4].Text = "Invitation Sent"; row.Cells[4].BackColor = System.Drawing.Color.Green; } else { string encryptedCouponCode = Encryption.Encrypt(u.CouponCode); if (encryptedCouponCode.Substring(encryptedCouponCode.Length - 2, 2) == "==") { encryptedCouponCode = encryptedCouponCode + "echo"; } encryptedCouponCode = encryptedCouponCode.Replace("+", "plus"); encryptedCouponCode = encryptedCouponCode.Replace(" ", "%20"); string messageBody = "Dear " + u.FirstName + ", Welcome to ECHO! You have been added to " + txtName.Text + " " + txtDesc.Text + " by" + currentUser.FirstName + " on EchoAttendance. Register using the following link: http://echocommunicator.com/account/register?cc=" + encryptedCouponCode + ". To download our mobile App click https://bit.ly/2RbXp5r"; string EmailBody = "Dear " + u.FirstName + ", <br/><br/>Welcome to ECHO!<br/><br/> You have been added to " + txtName.Text + " " + txtDesc.Text + " by" + currentUser.FirstName + " on EchoAttendance.<br/><br/> Register using the following link:http://echocommunicator.com/account/register?cc=" + encryptedCouponCode + " <br/><br/>to download our mobile App click https://bit.ly/2RbXp5r"; //string messageBody = "Dear " + u.FirstName + ", Welcome to ECHO! click this link to complete your Registration http://echocommunicator.com/account/register?cc=" + Encryption.Encrypt(u.CouponCode) + ""; //string EmailBody = "Dear " + u.FirstName + ", <br/><br/>Welcome to ECHO! click this link to complete your Registration<br/><br/> http://echocommunicator.com/account/register?cc=" + Encryption.Encrypt(u.CouponCode) + ""; try { General.SendSMS(row.Cells[2].Text.Trim(), messageBody); General.SendEmail(row.Cells[1].Text.Trim(), "Welcome to ECHO", EmailBody); } catch { } row.Cells[4].Text = "Invitation sent again"; row.Cells[4].BackColor = System.Drawing.Color.YellowGreen; } } else { row.Cells[4].Text = "Imported"; row.Cells[4].BackColor = System.Drawing.Color.Green; } //User uu = objUser; //} //else //{ // row.Cells[4].Text = "Invalid record"; // row.Cells[4].BackColor = System.Drawing.Color.Red; //} } else { row.Cells[4].Text = "Invalid record"; row.Cells[4].BackColor = System.Drawing.Color.Red; } } } Response.Redirect("~/account/managegroups"); } else { ErrorMessage.Text = "Invalid Contact file please upload a valid file!"; } } //MasterPage ac = this.Master; //ac.BindGroups(); //BindGroups(); } catch (Exception ex) { ErrorMessage.Text = ex.Message; } }
protected void Insert(object sender, EventArgs e) { //string input = Encryption.Decrypt("nJfH QEbkgjs3f1 M956og=="); //string encryptedCouponCode = Encryption.Encrypt(input); //if (encryptedCouponCode.Substring(encryptedCouponCode.Length - 2, 2) == "==") //{ // encryptedCouponCode = encryptedCouponCode + "echo"; //} //encryptedCouponCode = encryptedCouponCode.Replace("+", "plus"); //encryptedCouponCode = encryptedCouponCode.Replace(" ", "%20"); //General.SendSMS("9953624768", "Register using the following link: http://echocommunicator.com/account/register?cc=" + encryptedCouponCode); try { User currentUser = new UserController().GetUser(Context.User.Identity.Name); if (txtNewUserName.Text == "") { General.ShowAlertMessage("Name field is required!"); } else { if (isValidUser()) { User u = new User(); string strUserID = string.Empty; bool CreateMapping = true; bool success = false; if (txtMobileNo.Text != string.Empty && isExist(txtMobileNo.Text, txtNewUserName.Text)) { u = new UserController().GetUser_byNameAndMobile(txtMobileNo.Text.Trim(), txtNewUserName.Text.Trim()); strUserID = u.UserID; if (u.UserGroup.Select(ss => ss.UserGroupID).Contains(Convert.ToInt32(GroupID))) { CreateMapping = false; } } else { string CouponCode = GenerateCoupon(); u.FirstName = txtNewUserName.Text; u.EMail = txtEmailID.Text; u.MobileNo = txtMobileNo.Text; u.CreateDate = DateTime.Now; u.DOB = Convert.ToDateTime("1/1/1900"); u.LastLockoutDate = DateTime.Now; u.LastLoginDate = DateTime.Now; u.LastPasswordChangedDate = DateTime.Now; u.CouponCode = CouponCode; u.IsDeleted = false; u.IsLockedOut = false; u.RoleID = 4; u.Custom1 = txtRollNo.Text; u.Custom2 = ddlType.Text; u.Custom3 = ddlCast.Text; u.Custom4 = ddlHandicap.Text; u.Custom5 = "3";//This field is used Type of Flow that it should go u.PWD = Encryption.Encrypt("ab@345"); u.Session = General.GetCurrentSession; u.ClientID = currentUser.ClientID; strUserID = new UserController().CreateUser(u); } if (CreateMapping) { UserGroupMapping objUserGroupMapping = new UserGroupMapping(); objUserGroupMapping.UserGroupID = GroupID; objUserGroupMapping.UserID = strUserID; objUserGroupMapping.isAdmin = chkIsAdmin.Checked; string strMsg = new UserController().CreateUserGroupMapping(objUserGroupMapping); success = true; } if (success == true) { General.ShowAlertMessage("Success"); this.bindGvContacts(); txtNewUserName.Text = string.Empty;; txtEmailID.Text = string.Empty; txtMobileNo.Text = string.Empty; } else { ErrorMessage.Text = "Something is not right Please try again!"; } } else { General.ShowAlertMessage("Invalid User! Please verify the data and try again"); } } } catch (Exception ex) { ErrorMessage.Text = ex.Message; } }
public string CreateUserGroupMapping(UserGroupMapping _Mapping) { return(DataAccess.UserGroupMappingDao.CreateMapping(_Mapping).ToString()); }
public object AddUserToGroup(UserGroupViewModel gVM) { List <MessageModel> Messages = new List <MessageModel>(); using (LystenEntities db = new LystenEntities()) { UserGroupMapping UGM = new UserGroupMapping(); if (gVM.IsAdded == "1") { var obj = gVM.UsersId.Split(','); foreach (var item in obj) { int id = Convert.ToInt32(item); if (!db.UserGroupMappings.Any(x => x.UserId == id && x.GroupId == gVM.GroupId)) { UGM = new UserGroupMapping() { GroupId = gVM.GroupId, UserId = Convert.ToInt16(item) }; db.UserGroupMappings.Add(UGM); db.SaveChanges(); var group = db.Groups.Where(x => x.Id == gVM.GroupId).FirstOrDefault(); var userdetail = db.User_Master.Where(x => x.Id == UGM.UserId).FirstOrDefault(); if (group.GroupTypeId == 2) { if (userdetail.DeviceToken != null && userdetail.DeviceToken != "") { if (userdetail.DeviceType == "Android") { Helpers.NotificationHelper.sendMsgGroup(userdetail.Id, userdetail.DeviceToken, group.User_Master.FullName, group.Name, group.Id); } else { sendMsgGroup(userdetail.Id, userdetail.DeviceToken, group.User_Master.FullName, group.Name); } } } } } } else if (gVM.IsAdded == "0") { var obj = gVM.UsersId.Split(','); foreach (var item in obj) { int id = Convert.ToInt32(item); if (db.UserGroupMappings.Any(x => x.UserId == id && x.GroupId == gVM.GroupId)) { UGM = db.UserGroupMappings.Where(x => x.UserId == id && x.GroupId == gVM.GroupId).FirstOrDefault(); if (UGM != null) { db.Entry(UGM).State = EntityState.Deleted; db.SaveChanges(); } } } } else if (gVM.IsAdded == "2") { var obj = gVM.UsersId.Split(','); foreach (var item in obj) { int id = Convert.ToInt32(item); if (db.UserGroupMappings.Any(x => x.UserId == id && x.GroupId == gVM.GroupId)) { UGM = db.UserGroupMappings.Where(x => x.UserId == id && x.GroupId == gVM.GroupId).FirstOrDefault(); if (UGM != null) { db.Entry(UGM).State = EntityState.Deleted; db.SaveChanges(); } } } foreach (var item in obj) { int id = Convert.ToInt32(item); var newgroupdata = db.UserGroupMappings.Where(x => x.GroupId == gVM.GroupId).Select(x => x.Id).ToList(); var msgRdata = db.MessageRecipients.Where(x => x.RecipientGroupId == gVM.GroupId).ToList(); if (msgRdata.Count > 0) { foreach (var itemss in msgRdata) { var msgdata = db.Messages.Where(x => x.Id == itemss.MessageId).FirstOrDefault(); if (msgdata != null) { db.Entry(msgdata).State = EntityState.Deleted; db.SaveChanges(); } var Mdata = db.MessageRecipients.Where(x => x.Id == itemss.Id).FirstOrDefault(); if (Mdata != null) { db.Entry(Mdata).State = EntityState.Deleted; db.SaveChanges(); } } } foreach (var itemss in newgroupdata) { UGM = db.UserGroupMappings.Where(x => x.Id == itemss).FirstOrDefault(); if (UGM != null) { db.Entry(UGM).State = EntityState.Deleted; db.SaveChanges(); } } if (db.WebSocketSessionDbs.Any(x => x.GroupID == gVM.GroupId)) { var websocket = db.WebSocketSessionDbs.Where(x => x.GroupID == gVM.GroupId).FirstOrDefault(); db.Entry(websocket).State = EntityState.Deleted; db.SaveChanges(); } if (db.Groups.Any(x => x.Id == gVM.GroupId && x.CreatorId == id)) { var objdata = db.Groups.Where(x => x.Id == gVM.GroupId && x.CreatorId == id).FirstOrDefault(); db.Entry(objdata).State = EntityState.Deleted; db.SaveChanges(); } } } return(UGM); } }
protected void UploadContacts(object sender, EventArgs e) { if (fuContacts.HasFile) { if (fuContacts.FileName.EndsWith(".xls") || fuContacts.FileName.EndsWith(".xlsx")) { fuContacts.PostedFile.SaveAs(Server.MapPath("~/ContactsUpload/" + GroupID + fuContacts.PostedFile.FileName)); string ContactsFile = Server.MapPath("~/ContactsUpload/" + GroupID + fuContacts.PostedFile.FileName); var ConnectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0; Data Source = {0}; Extended Properties =Excel 12.0;", ContactsFile); var adapter = new OleDbDataAdapter("select * from [Contacts$]", ConnectionString); var ds = new DataSet(); adapter.Fill(ds, "Contacts"); DataTable contacts = ds.Tables["Contacts"]; DataColumn dc = new DataColumn("Status", typeof(string)); contacts.Columns.Add(dc); gvContactsFromXls.DataSource = contacts; gvContactsFromXls.DataBind(); gvContacts.DataSource = null; gvContacts.DataBind(); adapter.Dispose(); int AdminCount = 0; string duplicates = string.Empty; foreach (GridViewRow row in gvContactsFromXls.Rows) { if (row.RowType == DataControlRowType.DataRow) { if (IsValidRow(row)) { User u = null; //if (litFlowType.Text != "1" || row.Cells[7].Text.ToLower() == "yes") //{ if (row.Cells[5].Text != string.Empty && row.Cells[5].Text != " ") { u = new UserController().GetUserbyEmail(row.Cells[5].Text.Trim()); } if (u == null && row.Cells[4].Text != string.Empty && row.Cells[4].Text != " ") { u = new UserController().GetUserbyMobile(row.Cells[4].Text.Trim()); } //} //else //{ // if (u == null && row.Cells[1].Text != string.Empty && row.Cells[1].Text != " ") // { // u = new UserController().GetUser_byNameAndMobile(row.Cells[4].Text.Trim(), row.Cells[1].Text.Trim()); // } //} string strUserID = string.Empty; //User u = null; string couponCode = string.Empty; //this is for the case of siblings in same class with same number //bool createNewUser = false; //if (u != null) //{ // if (u.FirstName!= row.Cells[1].Text) // { // createNewUser = true; // } //} if (u == null) { User objUser = new User { CouponCode = couponCode, CreatedBy = Context.User.Identity.Name, CreateDate = DateTime.Now, DOB = Convert.ToDateTime("1/1/1900"), EMail = (row.Cells[5].Text == " ") ? string.Empty : row.Cells[5].Text, //row.Cells[1].Text?="": row.Cells[1].Text , FirstName = row.Cells[1].Text, IsDeleted = false, IsLockedOut = false, LastLockoutDate = DateTime.Now, LastLoginDate = DateTime.Now, LastName = string.Empty, LastPasswordChangedDate = DateTime.Now, MobileNo = row.Cells[4].Text, PWD = string.Empty, RoleID = 4, // UserGroup= listGroup,// for Normal user ImageID = string.Empty, Custom1 = row.Cells[0].Text.Replace(" ", string.Empty), //used for Roll Number Custom2 = row.Cells[6].Text.Replace(" ", string.Empty), //used for User Type(Gender or Teacher) Custom3 = row.Cells[3].Text.Replace(" ", string.Empty), //used for date of joining Custom4 = row.Cells[2].Text.Replace(" ", string.Empty), //used for Designation Custom5 = "1", Session = General.GetCurrentSession, ClientID = Convert.ToInt32(litClientID.Text) }; objUser.PWD = Encryption.Encrypt("ab@345"); strUserID = new UserController().CreateUser(objUser); } else { strUserID = u.UserID; } bool isAdmin = false; UserGroupMapping objUserGroupMapping = new UserGroupMapping(); objUserGroupMapping.UserGroupID = GroupID; objUserGroupMapping.UserID = strUserID; objUserGroupMapping.isAdmin = isAdmin; objUserGroupMapping.SerialNoForGroup = row.Cells[0].Text.Replace(" ", string.Empty);//will be used as serial number for that group; IList <UserGroupMapping> mlist = new UserController().GetUserGroupMapping(strUserID); mlist = mlist.Where(ss => ss.UserGroupID == GroupID).ToList(); if (row.Cells[7].Text.ToLower() == "yes" && AdminCount <= 5) { isAdmin = true; AdminCount++; } if (mlist.Count < 1) { objUserGroupMapping.isAdmin = isAdmin; string strMsg = new UserController().CreateUserGroupMapping(objUserGroupMapping); row.Cells[8].Text = "Imported"; row.Cells[8].BackColor = System.Drawing.Color.Green; } else { duplicates = u.MobileNo + ", " + duplicates; row.Cells[8].Text = "Duplicate"; row.Cells[8].BackColor = System.Drawing.Color.Yellow; } } else { row.Cells[8].Text = "Invalid record"; row.Cells[8].BackColor = System.Drawing.Color.Red; } } } gvContacts.DataSource = null; gvContacts.DataBind(); if (duplicates != string.Empty) { General.ShowAlertMessage("Import completed! Users with MobileNo " + duplicates + " Could not be import because they are duplicate mobile numbers"); } litBulkUploadResult.Text = "<h3>Bulk upload results</h3>"; ErrorMessage.Text = "Import completed! Users with MobileNo " + duplicates + " Could not be import because they are duplicate mobile numbers.<br/> The temporary password for the members are ab@345"; } else { ErrorMessage.Text = "Invalid Contact file please upload a valid file!"; } } }
protected void Insert(object sender, EventArgs e) { try { User currentUser = new UserController().GetUser(Context.User.Identity.Name); if (txtNewUserName.Text == "") { General.ShowAlertMessage("Name field is required!"); } else { if (isValidUser()) { User u = new User(); string strUserID = string.Empty; bool CreateMapping = true; bool success = false; bool isAdmin = Convert.ToBoolean(ddlIsAdmin.SelectedValue); if (txtMobileNo.Text != string.Empty) { u = new UserController().GetUserbyMobile(txtMobileNo.Text.Trim()); if (u != null) { strUserID = u.UserID; if (u.UserGroup.Select(ss => ss.UserGroupID).Contains(Convert.ToInt32(GroupID))) { CreateMapping = false; } } } if (txtEmailID.Text != string.Empty) { u = new UserController().GetUserbyEmail(txtEmailID.Text.Trim()); if (u != null) { strUserID = u.UserID; if (u.UserGroup.Select(ss => ss.UserGroupID).Contains(Convert.ToInt32(GroupID))) { CreateMapping = false; } } } if (u == null) { u = new BusinessObjects.User(); string CouponCode = string.Empty; u.FirstName = txtNewUserName.Text; u.EMail = txtEmailID.Text; u.MobileNo = txtMobileNo.Text; u.CreateDate = DateTime.Now; u.DOB = Convert.ToDateTime("1/1/1900"); u.LastLockoutDate = DateTime.Now; u.LastLoginDate = DateTime.Now; u.LastPasswordChangedDate = DateTime.Now; u.CouponCode = CouponCode; u.IsDeleted = false; u.IsLockedOut = false; u.PWD = Encryption.Encrypt("ab@345"); //if (litFlowType.Text == "1" && !isAdmin) //{ // u.IsLockedOut = true; // u.PWD = string.Empty; //} u.RoleID = 4; u.Custom1 = txtRollNo.Text; u.Custom2 = rdGender.SelectedValue; u.Custom3 = txtDOJ.Text; u.Custom4 = txtDesignation.Text; u.Custom5 = "1";//This field is used Type of Flow that it should go u.Session = General.GetCurrentSession; u.ClientID = Convert.ToInt32(litClientID.Text); strUserID = new UserController().CreateUser(u); } if (CreateMapping) { UserGroupMapping objUserGroupMapping = new UserGroupMapping(); objUserGroupMapping.UserGroupID = GroupID; objUserGroupMapping.UserID = strUserID; objUserGroupMapping.isAdmin = Convert.ToBoolean(ddlIsAdmin.SelectedValue); objUserGroupMapping.SerialNoForGroup = txtRollNo.Text; string strMsg = new UserController().CreateUserGroupMapping(objUserGroupMapping); success = true; } if (success == true) { General.ShowAlertMessage("Success"); this.bindGvContacts(); txtNewUserName.Text = string.Empty;; txtEmailID.Text = string.Empty; txtMobileNo.Text = string.Empty; ErrorMessage.Text = "The temporary password for the user is ab@345"; } else { ErrorMessage.Text = "This User already exists!"; } } else { General.ShowAlertMessage("Invalid User! Please verify the data and try again"); } } } catch (Exception ex) { ErrorMessage.Text = ex.Message; } }