private bool UpdateXMLRole(SecurityRole entryRole) { bool flag = false; CRMDb conn = new CRMDb(); RetrieveRole retrieveRole = new RetrieveRole(); //var role = db.securityRole.Find(SecurityRoleId); retrieveRole.role = entryRole; Root xmlFile = (Root)ParseXMLHelper.DeserializeXml(xmlPath, "file"); Root dbFile = new Root(); if (entryRole.XMLRole != null && entryRole.XMLRole != "") { dbFile = (Root)ParseXMLHelper.DeserializeXml(entryRole.XMLRole, "db"); dbFile = functionUpdateXML(xmlFile, dbFile); } retrieveRole.xmlRole = dbFile; SecurityRole securityRole = conn.securityRole.Find(retrieveRole.role.SecurityRoleId); securityRole.ModifiedOn = DateTime.Now; securityRole.ModifiedBy = new Guid(System.Web.HttpContext.Current.Session["CurrentUserID"].ToString()); //securityRole.BusinessUnitId = retrieveRole.role.BusinessUnitId; securityRole.XMLRole = ParseXMLHelper.SerializeXml(retrieveRole.xmlRole); securityRole.FileModifiedDate = DateTime.ParseExact(System.IO.File.GetLastWriteTime(Server.MapPath(xmlPath)).ToString("dd/MM/yyyy HH:mm:ss"), "dd/MM/yyyy HH:mm:ss", null); conn.Entry(securityRole).State = EntityState.Modified; conn.SaveChanges(); flag = true; return(flag); }
public ActionResult formSubmit(RetrieveRole model, string actionType) { List <string> errorMessage = new List <string>(); string successMessage = Resources.NotifResource.SecurityRoleSuccess; SecurityRole securityRole = new SecurityRole(); securityRole.Name = model.role.Name; securityRole.SecurityRoleId = model.role.SecurityRoleId; KeyValuePair <int, string> results = new KeyValuePair <int, string>(1, ""); if (actionType == "Create") { //Check if there is already role with the same name int compareRoleName = db.securityRole.Where(x => x.Name == model.role.Name).Count(); if (compareRoleName > 0) { var jsonData = new { flag = false, Message = "Security role tidak boleh sama" }; return(Json(jsonData)); } securityRole.BusinessUnitId = model.role.BusinessUnitId; securityRole.CreatedOn = DateTime.Now; securityRole.CreatedBy = new Guid(System.Web.HttpContext.Current.Session["CurrentUserID"].ToString()); securityRole.DeletionStateCode = 0; securityRole.Status = 0; securityRole.FileModifiedDate = DateTime.ParseExact(System.IO.File.GetLastWriteTime(Server.MapPath(xmlPath)).ToString("dd/MM/yyyy HH:mm:ss"), "dd/MM/yyyy HH:mm:ss", null); securityRole.XMLRole = ParseXMLHelper.SerializeXml(model.xmlRole); db.securityRole.Add(securityRole); db.SaveChanges(); results = new KeyValuePair <int, string>(0, "Role berhasil ditambahkan"); } else if (actionType == "Edit") { securityRole.ModifiedOn = DateTime.Now; securityRole.ModifiedBy = new Guid(System.Web.HttpContext.Current.Session["CurrentUserID"].ToString()); securityRole.BusinessUnitId = model.role.BusinessUnitId; securityRole.XMLRole = ParseXMLHelper.SerializeXml(model.xmlRole); securityRole.FileModifiedDate = DateTime.ParseExact(System.IO.File.GetLastWriteTime(Server.MapPath(xmlPath)).ToString("dd/MM/yyyy HH:mm:ss"), "dd/MM/yyyy HH:mm:ss", null); securityRole.DeletionStateCode = model.role.DeletionStateCode; securityRole.Status = model.role.Status; securityRole.CreatedBy = model.role.CreatedBy; securityRole.CreatedOn = model.role.CreatedOn; db.Entry(securityRole).State = EntityState.Modified; db.SaveChanges(); results = new KeyValuePair <int, string>(0, "Role berhasil diupdate"); } //else if (actionType == "Delete") //{ // //rcm.ModifiedBy_ID = new Guid(Session["CurrentUserID"].ToString()); // //results = sp.RequestCreationMatrix_Delete(rcm); //} if (results.Key == 0 || results.Key == 16 || results.Key == 6) { UrlHelper u = new UrlHelper(this.ControllerContext.RequestContext); string url = u.Action("Edit", "SecurityRole", new { id = securityRole.SecurityRoleId, success = successMessage }); string urlNew = u.Action("Create", "SecurityRole"); var jsonData = new { flag = true, Message = url, urlNew = urlNew }; return(Json(jsonData)); } else { var jsonData = new { flag = false, Message = results.Value.ToString() }; return(Json(jsonData)); } }