public ActionResult ChangeStatus(long?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Role role = db.Roles.Where(r => r.ID == id && r.ID > 12).SingleOrDefault();

            if (role == null)
            {
                return(HttpNotFound());
            }

            bool tempVar = true;

            if (role.IsActive)
            {
                tempVar = false;
            }

            role.IsActive = tempVar;

            db.Entry(role).State = EntityState.Modified;
            db.SaveChanges();

            Session["siteMsgTyp"] = "success";
            Session["siteMsg"]    = "The selected option status changed successfully.";

            return(RedirectToAction("Index", "Roles"));
        }
Exemplo n.º 2
0
        public ActionResult ChangeStatus(long?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            User user = db.Users.Find(id);

            if (user == null)
            {
                return(HttpNotFound());
            }

            bool tempVar = true;

            if (user.IsActive)
            {
                tempVar = false;
            }

            user.IsActive = tempVar;

            db.Entry(user).State = EntityState.Modified;
            db.SaveChanges();

            Session["siteMsgTyp"] = "success";
            Session["siteMsg"]    = "The selected option status changed successfully.";

            return(RedirectToAction("Index", "Users"));
        }
        public ActionResult ActivateLine(string EmailId)
        {
            if (db.Users.Where(a => a.LoginName == EmailId).Count() > 0)
            {
                User user = db.Users.Where(a => a.LoginName == EmailId).Single();
                if (user.IsActive == true)
                {
                    return(RedirectToAction("Login", "Account"));
                }
                else
                {
                    user.IsActive        = true;
                    user.ModifiedDate    = DateTime.Now;
                    db.Entry(user).State = EntityState.Modified;
                    db.SaveChanges();
                    Session["siteMsgTyp"] = "success";
                    Session["siteMsg"]    = "Your Login Activate successfully. Please Login in.";
                    return(RedirectToAction("Login", "Account"));
                }
            }

            else
            {
                Session["siteMsgTyp"] = "error";
                Session["siteMsg"]    = "Your Login not  Activate successfully.Invalid Infromation.";
                return(RedirectToAction("Login", "Account"));
            }
        }
Exemplo n.º 4
0
        public static void AddToUserLog(string str, long usrID = 0)
        {
            long u = (long)val(GetCurrentUserDetails("ID"));

            if (u > 0)
            {
                usrID = u;
            }

            if (usrID > 0)
            {
                UserLog usrlg = new UserLog
                {
                    AccessDate = DateTime.Now,
                    AccessIP   = HttpContext.Current.Request.UserHostAddress,
                    AccessType = str,
                    UserID     = usrID
                };
                using (DBAuthContext db = new DBAuthContext())
                {
                    db.UserLogs.Add(usrlg);
                    db.SaveChanges();
                }
            }
        }
Exemplo n.º 5
0
        public static void PopulatePermission()
        {
            Assembly asm = Assembly.GetAssembly(typeof(Cremcircle.MvcApplication));

            var controlleractionlist = asm.GetTypes()
                                       .Where(type => typeof(System.Web.Mvc.Controller).IsAssignableFrom(type))
                                       .SelectMany(type => type.GetMethods(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public))
                                       .Where(m => !m.GetCustomAttributes(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute), true).Any())
                                       .Select(x => new { Controller = x.DeclaringType.Name, Action = x.Name, ReturnType = x.ReturnType.Name, Attributes = String.Join(",", x.GetCustomAttributes().Select(a => a.GetType().Name.Replace("Attribute", ""))) })
                                       .OrderBy(x => x.Controller).ThenBy(x => x.Action).ToList();

            //HttpContext.Current.Response.Write("<table width='100%' cellspacing='5' cellpadding='5' border='1'><tr><td>Ctr</td><td>Controller</td><td>Action</td><td>Attributes</td><td>ReturnType</td></tr>");
            //int ctr = 1;
            foreach (var item in controlleractionlist)
            {
                if (item.Attributes.Contains("AuthorizeUserRoles"))
                {
                    //HttpContext.Current.Response.Write("<tr><td>" + ctr + "</td><td>" + item.Controller + "</td><td>" + item.Action + "</td><td>" + item.Attributes + "</td><td>" + item.ReturnType + "</td></tr>");
                    //ctr++;
                    // Add to the permissions table
                    using (DBAuthContext db = new DBAuthContext())
                    {
                        //check if exixting
                        var existingPermissionCount = db.Permissions.Count(pe => pe.GroupName == "Object Level" && pe.ControllerName == item.Controller && pe.ActionName == item.Action);
                        if (existingPermissionCount == 0)
                        {
                            Permission pe = new Permission
                            {
                                GroupName       = "Object Level",
                                ControllerName  = item.Controller,
                                ActionName      = item.Action,
                                OnlyAdminHidden = false
                            };

                            db.Permissions.Add(pe);
                            db.SaveChanges();
                        }
                    }
                }
            }
            //HttpContext.Current.Response.Write("</table>");
            //HttpContext.Current.Response.End();
        }