private void editAgentType(HttpContext context, int intID) { string output = ""; try { var JsonStr = context.Request["models"]; List <clsAgentType> AgentTypes = JsonConvert.DeserializeObject <List <clsAgentType> >(JsonStr); using (ERP_CMSEntities cntx = new ERP_CMSEntities()) { string strName = AgentTypes[0].AgentType1.Trim().ToLower(); int agentTypeID = Convert.ToInt32(AgentTypes[0].AgentTypeID); var obj = (from tbl in cntx.AgentTypes where tbl.IsDeleted == false && tbl.AgentTypeID != agentTypeID && tbl.AgentType1.Trim().ToLower() == strName select tbl).FirstOrDefault(); if (obj == null) { var objAgentTypes = cntx.AgentTypes.Where(f => f.AgentTypeID == agentTypeID).ToList().FirstOrDefault(); // Dim objBrands = New PortalModel.Brands With {.BrandID = Brands(0).BrandID} var objAgentTypesOld = new ERP_CMSEntities().AgentTypes.Where(f => f.AgentTypeID == agentTypeID).ToList().FirstOrDefault(); cntx.AgentTypes.Attach(objAgentTypes); { //var withBlock = objBrands; objAgentTypes.AgentType1 = AgentTypes[0].AgentType1; } cntx.SaveChanges(); try { // PortalUtilities.fnCompare((object)objBrandsOld, (object)objBrands, objBrands.BrandID, lstEmployeeAndCompanyID(0)); } catch (Exception ex) { } context.Response.ContentType = "application/json; charset=utf-8"; context.Response.Write(JsonStr); } else { context.Response.ContentType = "application/json; charset=utf-8"; Newtonsoft.Json.Linq.JObject objErr = new Newtonsoft.Json.Linq.JObject(); objErr.Add("Errors", "Agent Type Already Exist!"); context.Response.Write(objErr.ToString()); } } } catch (Exception ex) { context.Response.ContentType = "application/json; charset=utf-8"; Newtonsoft.Json.Linq.JObject objErr = new Newtonsoft.Json.Linq.JObject(); objErr.Add("Errors", ex.Message); context.Response.Write(objErr.ToString()); } }
private void addShipper(HttpContext context, int intID) { string output = ""; try { var JsonStr = context.Request["models"]; List <clsShipper> Shippers = JsonConvert.DeserializeObject <List <clsShipper> >(JsonStr); using (ERP_CMSEntities cntx = new ERP_CMSEntities()) { string shipperContact1 = Shippers[0].Contact1; var obj = (from tbl in cntx.Shippers where tbl.IsDeleted == false && tbl.Contact1 == shipperContact1 select tbl).FirstOrDefault(); if (obj == null) { var objShipper = new ERP_CMS.DB_Code.Shipper() { Shipper_Name = Shippers[0].Shipper_Name, Shipper_Address = Shippers[0].Shipper_Address, Shipper_Email = Shippers[0].Shipper_Email, Contact1 = Shippers[0].Contact1, Contact2 = Shippers[0].Contact2, IsDeleted = false, InsertedDate = DateTime.Now, InsertedBy = userID }; cntx.Shippers.Add(objShipper); cntx.SaveChanges(); context.Response.ContentType = "application/json; charset=utf-8"; context.Response.Write(JsonStr); } else { context.Response.ContentType = "application/json; charset=utf-8"; Newtonsoft.Json.Linq.JObject objErr = new Newtonsoft.Json.Linq.JObject(); objErr.Add("Errors", "Shipper Already Exists!"); context.Response.Write(objErr.ToString()); } } } catch (Exception ex) { context.Response.ContentType = "application/json; charset=utf-8"; Newtonsoft.Json.Linq.JObject objErr = new Newtonsoft.Json.Linq.JObject(); objErr.Add("Errors", ex.Message); context.Response.Write(objErr.ToString()); } }
private void addAgentType(HttpContext context, int intID) { string output = ""; try { var JsonStr = context.Request["models"]; List <clsAgentType> AgentTypes = JsonConvert.DeserializeObject <List <clsAgentType> >(JsonStr); using (ERP_CMSEntities cntx = new ERP_CMSEntities()) { string strName = AgentTypes[0].AgentType1.Trim().ToLower(); var obj = (from tbl in cntx.AgentTypes where tbl.IsDeleted == false && tbl.AgentType1.Trim().ToLower() == strName select tbl).FirstOrDefault(); if (obj == null) { var objAgentType = new ERP_CMS.DB_Code.AgentType() { AgentType1 = AgentTypes[0].AgentType1, IsDeleted = false, InsertedDate = DateTime.Now, InsertedBy = userID }; cntx.AgentTypes.Add(objAgentType); cntx.SaveChanges(); context.Response.ContentType = "application/json; charset=utf-8"; context.Response.Write(JsonStr); } else { context.Response.ContentType = "application/json; charset=utf-8"; Newtonsoft.Json.Linq.JObject objErr = new Newtonsoft.Json.Linq.JObject(); objErr.Add("Errors", "Agent Type Already Exists!"); context.Response.Write(objErr.ToString()); } } } catch (Exception ex) { context.Response.ContentType = "application/json; charset=utf-8"; Newtonsoft.Json.Linq.JObject objErr = new Newtonsoft.Json.Linq.JObject(); objErr.Add("Errors", ex.Message); context.Response.Write(objErr.ToString()); } }
protected void grdAssignedRights_RowDeleting(object sender, System.Web.UI.WebControls.GridViewDeleteEventArgs e) { using (ERP_CMSEntities cntx = new ERP_CMSEntities()) { int id = int.Parse(grdAssignedRights.DataKeys[e.RowIndex].Value.ToString()); int intUserID = int.Parse(ddlUser.SelectedValue); lblStatus.Text = string.Empty; lblMsg.Text = string.Empty; try { // Dim obj = New PortalModel.EmpLinks With {.EmpLinkID = id} var obj = cntx.UserLinks.Where(f => f.UserLinkID == id).ToList().FirstOrDefault(); int intMenuLinkID = (int)obj.MenuLinkID; cntx.UserLinks.Attach(obj); cntx.UserLinks.Remove(obj); var objInner = cntx.sp_GetPageRightsByUserAndMenuLinkID(intUserID, intMenuLinkID).Where(f => f.UserRightID > 0).ToList(); foreach (var o in objInner) { var objEmpRights = cntx.UserRights.Where(f => f.PageRightID == o.PageRightID).ToList().FirstOrDefault(); { cntx.UserRights.Attach(objEmpRights); cntx.UserRights.Remove(objEmpRights); } } cntx.SaveChanges(); GetRights(cntx); lblStatus.ForeColor = System.Drawing.Color.DarkGreen; lblStatus.Text = "Right Deleted Successfully."; lblMsg.Text = "Right Deleted Successfully."; } catch (Exception ex) { lblStatus.ForeColor = System.Drawing.Color.Red; lblStatus.Text = ex.Message; } } }
protected void btnSave_Click(object sender, System.EventArgs e) { if (Page.IsValid) { bool UserCreated = false; try { using (ERP_CMSEntities cntx = new ERP_CMSEntities()) { string password = EncryptionHelper.Encrypt("ERP_CMS2k18", txtPassword.Text); var user = new User() { UserName = txtLoginName.Text, Password = password, IsActive = true, IsAdmin = false, IsDeleted = false }; cntx.Users.Add(user); cntx.SaveChanges(); UserCreated = true; } lblStatus.ForeColor = System.Drawing.Color.DarkGreen; lblStatus.Text = "User Created Successfully..."; txtLoginName.Text = string.Empty; txtPassword.Text = string.Empty; txtConfirmPassword.Text = string.Empty; } catch (Exception ex) { lblStatus.ForeColor = System.Drawing.Color.Red; lblStatus.Text = ex.Message; if (UserCreated) { //delete that user } } } }
protected void btnChangePassword_Click(object sender, System.EventArgs e) { try { using (ERP_CMSEntities cntx = new ERP_CMSEntities()) { int userID = getCurrentUserID(); var user = cntx.Users.Find(userID); string resetPassword = EncryptionHelper.Encrypt("ERP_CMS2k18", txtPassword.Text); user.Password = resetPassword; cntx.SaveChanges(); lblStatus.Text = "Password changed successfully"; lblStatus.ForeColor = System.Drawing.Color.DarkGreen; } } catch (Exception ex) { lblStatus.ForeColor = System.Drawing.Color.Red; lblStatus.Text = ex.Message; } }
private void deleteAgentType(HttpContext context, int intID) { string output = ""; try { var JsonStr = context.Request["models"]; List <clsAgentType> AgentTypes = JsonConvert.DeserializeObject <List <clsAgentType> >(JsonStr); using (ERP_CMSEntities cntx = new ERP_CMSEntities()) { var objAgentTypes = new ERP_CMS.DB_Code.AgentType() { AgentTypeID = Convert.ToInt32(AgentTypes[0].AgentTypeID) }; //objAgentTypes.DeletedBy = userID; // Dim objBrands = New PortalModel.Brands With {.BrandID = intID} cntx.AgentTypes.Attach(objAgentTypes); objAgentTypes.IsDeleted = true; objAgentTypes.DeletedBy = userID; objAgentTypes.DeletedDate = DateTime.Now; // cntx.Brands.DeleteObject(objBrands) cntx.SaveChanges(); } context.Response.ContentType = "application/json; charset=utf-8"; context.Response.Write(JsonStr); } catch (Exception ex) { context.Response.ContentType = "application/json; charset=utf-8"; Newtonsoft.Json.Linq.JObject objErr = new Newtonsoft.Json.Linq.JObject(); objErr.Add("Errors", ex.Message); context.Response.Write(objErr.ToString()); } }
private void editShipper(HttpContext context, int intID) { string output = ""; try { var JsonStr = context.Request["models"]; List <clsShipper> Shippers = JsonConvert.DeserializeObject <List <clsShipper> >(JsonStr); using (ERP_CMSEntities cntx = new ERP_CMSEntities()) { string shipperContact1 = Shippers[0].Contact1; int shipperID = Convert.ToInt32(Shippers[0].ShipperID); var obj = (from tbl in cntx.Shippers where tbl.IsDeleted == false && tbl.ShipperID != shipperID && tbl.Contact1 == shipperContact1 select tbl).FirstOrDefault(); if (obj == null) { var objShipper = cntx.Shippers.Where(f => f.ShipperID == shipperID).ToList().FirstOrDefault(); // Dim objBrands = New PortalModel.Brands With {.BrandID = Brands(0).BrandID} var objShipperOld = new ERP_CMSEntities().Shippers.Where(f => f.ShipperID == shipperID).ToList().FirstOrDefault(); cntx.Shippers.Attach(objShipper); { //var withBlock = objBrands; objShipper.Shipper_Name = Shippers[0].Shipper_Name; objShipper.Shipper_Address = Shippers[0].Shipper_Address; objShipper.Shipper_Email = Shippers[0].Shipper_Email; objShipper.Contact1 = Shippers[0].Contact1; objShipper.Contact2 = Shippers[0].Contact2; } cntx.SaveChanges(); try { // PortalUtilities.fnCompare((object)objBrandsOld, (object)objBrands, objBrands.BrandID, lstEmployeeAndCompanyID(0)); } catch (Exception ex) { } context.Response.ContentType = "application/json; charset=utf-8"; context.Response.Write(JsonStr); } else { context.Response.ContentType = "application/json; charset=utf-8"; Newtonsoft.Json.Linq.JObject objErr = new Newtonsoft.Json.Linq.JObject(); objErr.Add("Errors", "Shipper Already Exist!"); context.Response.Write(objErr.ToString()); } } } catch (Exception ex) { context.Response.ContentType = "application/json; charset=utf-8"; Newtonsoft.Json.Linq.JObject objErr = new Newtonsoft.Json.Linq.JObject(); objErr.Add("Errors", ex.Message); context.Response.Write(objErr.ToString()); } }
protected void grd_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e) { if (e.CommandName == "chngStatus") { try { int RowIndex = int.Parse(e.CommandArgument.ToString()); int UserID = int.Parse(grd.DataKeys[RowIndex]["UserID"].ToString()); string UserName = grd.Rows[RowIndex].Cells[0].Text; using (ERP_CMSEntities cntx = new ERP_CMSEntities()) { //var usr = cntx.Users.Where(f => f.UserName == UserName).Select(f => f.UserName).FirstOrDefault(); var usr = cntx.Users.Find(UserID); if (UserName == "admin") { lblStatus.ForeColor = System.Drawing.Color.Red; lblStatus.Text = "admin user can not be blocked."; } else { usr.IsActive = !usr.IsActive; cntx.SaveChanges(); lblStatus.ForeColor = System.Drawing.Color.DarkGreen; lblStatus.Text = "User status has been updated."; GetUsers(cntx, UserID); } } //MembershipUser usr = Membership.GetUser(UserName); } catch (Exception ex) { lblStatus.ForeColor = System.Drawing.Color.Red; lblStatus.Text = ex.Message; } } else if (e.CommandName == "chngPwd") { try { int RowIndex = int.Parse(e.CommandArgument.ToString()); int UserID = int.Parse(grd.DataKeys[RowIndex]["UserID"].ToString()); string UserName = grd.Rows[RowIndex].Cells[0].Text; //MembershipUser usr = Membership.GetUser(UserName); using (ERP_CMSEntities cntx = new ERP_CMSEntities()) { //var usr = cntx.Users.Where(f => f.UserName == UserName).Select(f => f.UserName).FirstOrDefault(); string newPassword = PortalUtilities.resetPassword(cntx, UserID); } lblStatus.Text = "Password updated with: " + UserName + "@12345"; lblStatus.ForeColor = System.Drawing.Color.DarkGreen; } catch (Exception ex) { lblStatus.ForeColor = System.Drawing.Color.Red; lblStatus.Text = ex.Message; } } }
protected void btnSave_Click(object sender, System.EventArgs e) { try { lblStatus.Text = ""; lblMsg.Text = ""; int intUserId = int.Parse(ddlUser.SelectedValue); int intMenuLinkID; using (ERP_CMSEntities cntx = new ERP_CMSEntities()) { foreach (GridViewRow row in grdNonAssignedRights.Rows) { CheckBox chk = (CheckBox)row.FindControl("chkLink"); if (chk.Checked == true) { intMenuLinkID = int.Parse(grdNonAssignedRights.DataKeys[row.RowIndex].Value.ToString()); var objUserLinks = new UserLink() { UserID = intUserId, MenuLinkID = intMenuLinkID //UserID = intUserId, //objUserLinks.MenuLinkID = intMenuLinkID; }; cntx.UserLinks.Add(objUserLinks); cntx.SaveChanges(); // Dim rptInnerRights As Repeater = row.FindControl("rptInnerRights") // For Each rptItem As RepeaterItem In rptInnerRights.Items // Dim chkInner As CheckBox = rptItem.FindControl("chkInnerLink") // If chkInner.Checked Then // Dim objEmpRights As New PortalModel.EmpRights // Dim intPageRightID As Integer = DirectCast(rptItem.FindControl("hdnPageRightID"), HiddenField).Value // With objEmpRights // .EmployeeID = intUserID // .PageRightID = intPageRightID // End With // cntx.EmpRights.AddObject(objEmpRights) // End If // Next GridView grdInnerRights = (GridView)row.FindControl("grdNonAssignedRightsInner"); foreach (GridViewRow rptItem in grdInnerRights.Rows) { try { CheckBox chkInner = (CheckBox)rptItem.FindControl("chkInnerLink"); int intPageRightID = int.Parse(((HiddenField)rptItem.FindControl("hdnPageRightID")).Value); if (chkInner.Checked) { var objUserRights = new UserRight(); { //var withBlock = objEmpRights; objUserRights.UserID = intUserId; objUserRights.PageRightID = intPageRightID; } cntx.UserRights.Add(objUserRights); } else { var objExisting = cntx.UserRights.Where(f => f.UserID == intUserId && f.PageRightID == intPageRightID).ToList().FirstOrDefault(); if (objExisting != null) { cntx.UserRights.Remove(objExisting); } } } catch (Exception ex) { } } } } foreach (GridViewRow rowParent in grdAssignedRights.Rows) { GridView grdInner = (GridView)rowParent.FindControl("grdAssignedRightsInner"); int MenuLinkID = int.Parse(((HiddenField)rowParent.FindControl("hdnMenuLinkID")).Value); foreach (GridViewRow row in grdInner.Rows) { CheckBox chkInner = (CheckBox)row.FindControl("chkInnerLink"); try { int intPageRightID = int.Parse(((HiddenField)row.FindControl("hdnPageRightID")).Value); var objExistingList = cntx.UserRights.Where(f => f.UserID == intUserId && f.PageRightID == intPageRightID).ToList(); foreach (var objExisting in objExistingList) { cntx.UserRights.Remove(objExisting); cntx.SaveChanges(); } if (chkInner.Checked) { var objUserRights = new UserRight(); { objUserRights.UserID = intUserId; objUserRights.PageRightID = intPageRightID; } cntx.UserRights.Add(objUserRights); } } catch (Exception ex) { } } } cntx.SaveChanges(); GetRights(cntx); lblMsg.ForeColor = System.Drawing.Color.DarkGreen; lblMsg.Text = "Rights updated successfully..."; } } catch (Exception ex) { } }