public static void SaveRoles(SystemRole role)
 {
     using (var ctx = new BMIKidsEntities(ConnectionString))
     {
         try
         {
             ctx.SystemRoles.ApplyChanges(role);
             ctx.SaveChanges();
         }
         catch (Exception ex)
         {
             LogUtility.WriteEntryEventLog("SaveRoles_DataProvider_UpdateTransaction", ex, EventLogEntryType.Information);
             if (ex.InnerException != null)
                 throw ex.InnerException;
             throw;
         }
     }
 }
Ejemplo n.º 2
0
        protected void CreateEditBtn_Click(object sender, EventArgs e)
        {
            string action = UtilityMethod.GetRequestParameter("act");
            if (Page.IsValid)
            {
                if (action.ToLower() == "edit")
                {
                    int roleId = -1;
                    if (UtilityMethod.GetRequestParameter("role").IsInt32())
                        roleId = Convert.ToInt32(UtilityMethod.GetRequestParameter("role"));

                    SystemRole role = SystemUser_DataProvider.GetRoles(roleId).FirstOrDefault();
                    if (role != null)
                    {
                        role.MarkAsModified();
                        role.RoleDescription = descriptionTxt.Text;
                        role.RoleName = roleNameTxt.Text;

                        SystemUser_DataProvider.SaveRoles(role);
                        Page.Response.Redirect("AdminRoles.aspx");
                    }
                    else
                        throw new InvalidOperationException();
                }
                else if (action.ToLower() == "delete")
                {
                    int roleId = -1;
                    if (UtilityMethod.GetRequestParameter("role").IsInt32())
                        roleId = UtilityMethod.GetRequestParameter("role").ToInt32();

                    SystemRole role = SystemUser_DataProvider.GetRoles(roleId).FirstOrDefault();
                    role.MarkAsDeleted();
                    SystemUser_DataProvider.SaveRoles(role);
                    Page.Response.Redirect("AdminRoles.aspx");
                }
                else if (action.ToLower() == "new")
                {
                    SystemRole role = new SystemRole { RoleName = roleNameTxt.Text, RoleDescription = descriptionTxt.Text };
                    SystemUser_DataProvider.SaveRoles(role);
                    Page.Response.Redirect("AdminRoles.aspx");
                }
            }
        }