예제 #1
0
        public bool ValidateUser(string username, string password)
        {
            using (KlmsnContext db = new KlmsnContext())
            {
                var result = from u in db.Users where (u.UserName == username) select u;

                if (result.Count() != 0)
                {
                    var dbuser = result.First();

                    if (dbuser.Password == CreatePasswordHash(password, dbuser.PasswordSalt))
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
        }
예제 #2
0
        public bool HasPerm(int userID, string customPerm)
        {
            using (KlmsnContext db = new KlmsnContext())
            {
                //kendisinin var mi?
                var user_       = db.Users.Find(userID);
                var user_perms  = user_.CustomPermissions.ToList();
                var usergroups_ = user_.UserGroups.ToList();
                foreach (UserGroup group_ in usergroups_)
                {
                    foreach (CustomPermission cp_ in group_.CustomPermissions.ToList())
                    {
                        user_perms.Add(cp_);
                    }
                }

                db.Dispose();
                foreach (CustomPermission cp in user_perms)
                {
                    if (cp.Description.Equals(customPerm))
                    {
                        return(true);
                    }
                }

                //gruplarinin var mi?

                return(false);
            }
        }
예제 #3
0
        public MembershipUser CreateUser(string username, string firstname, string lastname, string password, string email)
        {
            using (KlmsnContext db = new KlmsnContext())
            {
                User user = new User();

                user.UserName          = username;
                user.FirstName         = firstname;
                user.LastName          = lastname;
                user.Email             = email;
                user.PasswordSalt      = CreateSalt();
                user.Password          = CreatePasswordHash(password, user.PasswordSalt);
                user.CreatedDate       = DateTime.Now;
                user.IsActivated       = false;
                user.IsLockedOut       = false;
                user.LastLockedOutDate = DateTime.Now;
                user.LastLoginDate     = DateTime.Now;

                db.Users.Add(user);
                db.Entry(user).State = System.Data.EntityState.Added;
                db.SaveChanges();

                var user_role = db.Roles.Find(3);
                user_role.Users.Add(user);
                db.SaveChanges();

                return(GetUser(username));
            }
        }
예제 #4
0
        public MembershipUser CreateUser(string username, string firstname, string lastname, string password, string email)
        {
            using (KlmsnContext db = new KlmsnContext())
            {
                User user = new User();

                user.UserName = username;
                user.FirstName = firstname;
                user.LastName = lastname;
                user.Email = email;
                user.PasswordSalt = CreateSalt();
                user.Password = CreatePasswordHash(password, user.PasswordSalt);
                user.CreatedDate = DateTime.Now;
                user.IsActivated = false;
                user.IsLockedOut = false;
                user.LastLockedOutDate = DateTime.Now;
                user.LastLoginDate = DateTime.Now;

                db.Users.Add(user);
                db.Entry(user).State = System.Data.EntityState.Added;
                db.SaveChanges();

                var user_role = db.Roles.Find(3);
                user_role.Users.Add(user);
                db.SaveChanges();

                return GetUser(username);
            }
        }
예제 #5
0
 public string GetParentDescription(int? parent_id)
 {
     int? parentID = parent_id;
     if (parentID == null)
     {
         return "--";
     }
     else
     {
         KlmsnContext db = new KlmsnContext();
         var item = db.RequestTypes.Find(parentID);
         return item.Description;
     }
 }
예제 #6
0
        public string GetParentDescription(int?parent_id)
        {
            int?parentID = parent_id;

            if (parentID == null)
            {
                return("--");
            }
            else
            {
                KlmsnContext db   = new KlmsnContext();
                var          item = db.RequestTypes.Find(parentID);
                return(item.Description);
            }
        }
예제 #7
0
        public IEnumerable<TreeViewItem> GetEmployees(TreeViewItem node)
        {
            var db = new KlmsnContext();
            int? parentId = !string.IsNullOrEmpty(node.Value) ? (int?)Convert.ToInt32(node.Value) : null;

            IEnumerable<TreeViewItem> nodes = from item in db.RequestTypes
                                where item.ParentRequestTypeId == parentId || (parentId == null)
                                select new TreeViewItem
                                {
                                    Text = item.Description,
                                    Value = item.RequestTypeID.ToString(),
                                    Enabled = true
                                    //LoadOnDemand = item.Employees.Count > 0
                                };

            return nodes;
        }
예제 #8
0
        public MembershipUser GetUser(string username)
        {
            using (KlmsnContext db = new KlmsnContext())
            {
                var result = from u in db.Users where (u.UserName == username) select u;

                if (result.Count() != 0)
                {
                    var dbuser = result.FirstOrDefault();

                    string   _username                = dbuser.UserName;
                    int      _providerUserKey         = dbuser.UserId;
                    string   _email                   = dbuser.Email;
                    string   _passwordQuestion        = "";
                    string   _comment                 = dbuser.Comments;
                    bool     _isApproved              = dbuser.IsActivated;
                    bool     _isLockedOut             = dbuser.IsLockedOut;
                    DateTime _creationDate            = dbuser.CreatedDate;
                    DateTime _lastLoginDate           = dbuser.LastLoginDate.GetValueOrDefault(DateTime.Now);
                    DateTime _lastActivityDate        = DateTime.Now;
                    DateTime _lastPasswordChangedDate = DateTime.Now;
                    DateTime _lastLockedOutDate       = dbuser.LastLockedOutDate.GetValueOrDefault(DateTime.Now);

                    MembershipUser user = new MembershipUser("CustomMembershipProvider",
                                                             _username,
                                                             _providerUserKey,
                                                             _email,
                                                             _passwordQuestion,
                                                             _comment,
                                                             _isApproved,
                                                             _isLockedOut,
                                                             _creationDate,
                                                             _lastLoginDate,
                                                             _lastActivityDate,
                                                             _lastPasswordChangedDate,
                                                             _lastLockedOutDate
                                                             );

                    return(user);
                }
                else
                {
                    return(null);
                }
            }
        }
예제 #9
0
        public IEnumerable <TreeViewItem> GetEmployees(TreeViewItem node)
        {
            var db       = new KlmsnContext();
            int?parentId = !string.IsNullOrEmpty(node.Value) ? (int?)Convert.ToInt32(node.Value) : null;

            IEnumerable <TreeViewItem> nodes = from item in db.RequestTypes
                                               where item.ParentRequestTypeId == parentId || (parentId == null)
                                               select new TreeViewItem
            {
                Text    = item.Description,
                Value   = item.RequestTypeID.ToString(),
                Enabled = true
                          //LoadOnDemand = item.Employees.Count > 0
            };

            return(nodes);
        }
예제 #10
0
        public bool isInRole(int userID, string roleName)
        {
            using (KlmsnContext db = new KlmsnContext())
            {
                var user_ = db.Users.Find(userID);

                var user_roles = user_.Roles.ToList();
                db.Dispose();
                foreach (Role rl in user_roles)
                {
                    if (rl.Description.ToLower() == roleName.ToLower())
                    {
                        return(true);
                    }
                }
                return(false);
            }
        }
예제 #11
0
        public User GetCustomUser(string username)
        {
            using (KlmsnContext db = new KlmsnContext())
            {
                var result = from u in db.Users where (u.UserName == username) select u;

                if (result.Count() != 0)
                {
                    var dbuser = result.FirstOrDefault();

                    return dbuser;
                }
                else
                {
                    return null;
                }
            }
        }
예제 #12
0
        public bool HasModuleAccess(string username, int moduleId)
        {
            using (KlmsnContext db = new KlmsnContext())
            {
                try
                {
                    var result = (from u in db.Users where (u.UserName == username) select u).FirstOrDefault();
                    int xsay   = result.Modules.Where(i => i.ModuleID == moduleId).Count();

                    if (xsay > 0)
                    {
                        return(true);
                    }
                }
                catch { return(false); }
            }
            return(false);
        }
예제 #13
0
        public User GetCustomUser(string username)
        {
            using (KlmsnContext db = new KlmsnContext())
            {
                var result = from u in db.Users where (u.UserName == username) select u;

                if (result.Count() != 0)
                {
                    var dbuser = result.FirstOrDefault();

                    return(dbuser);
                }
                else
                {
                    return(null);
                }
            }
        }
예제 #14
0
        public IList <Role> GetRoles(string username)
        {
            using (KlmsnContext db = new KlmsnContext())
            {
                var result = from u in db.Users where (u.UserName == username) select u;

                if (result.Count() != 0)
                {
                    var dbuser = result.FirstOrDefault();

                    return(dbuser.Roles.ToList());
                }
                else
                {
                    return(null);
                }
            }
        }
예제 #15
0
        public string GetUserNameByEmail(string email)
        {
            using (KlmsnContext db = new KlmsnContext())
            {
                var result = from u in db.Users where (u.Email == email) select u;

                if (result.Count() != 0)
                {
                    var dbuser = result.FirstOrDefault();

                    return(dbuser.UserName);
                }
                else
                {
                    return("");
                }
            }
        }
예제 #16
0
 public bool changePass(string userName, string oldPass, string newPass)
 {
     using (KlmsnContext db = new KlmsnContext())
     {
         bool xdurum = ValidateUser(userName, oldPass);
         if (xdurum && newPass.Length >= 6)
         {
             User user = db.Users.Where(i => i.UserName == userName).SingleOrDefault();
             user.PasswordSalt = CreateSalt();
             user.Password     = CreatePasswordHash(newPass, user.PasswordSalt);
             db.SaveChanges();
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
예제 #17
0
 public string resetPass(string userName)
 {
     using (KlmsnContext db = new KlmsnContext())
     {
         try
         {
             User user = db.Users.Where(i => i.UserName == userName).SingleOrDefault();
             user.PasswordSalt = CreateSalt();
             user.Password     = CreatePasswordHash("123456", user.PasswordSalt);
             db.SaveChanges();
             db.Dispose();
             return("123456");
         }
         catch
         {
             return("Şifre Sıfırlamada Hata");
         }
     }
 }
예제 #18
0
 public bool changePass(string userName, string oldPass, string newPass)
 {
     using (KlmsnContext db = new KlmsnContext())
     {
         bool xdurum = ValidateUser(userName, oldPass);
         if (xdurum && newPass.Length >= 6)
         {
             User user = db.Users.Where(i => i.UserName == userName).SingleOrDefault();
             user.PasswordSalt = CreateSalt();
             user.Password = CreatePasswordHash(newPass, user.PasswordSalt);
             db.SaveChanges();
             return true;
         }
         else
         {
             return false;
         }
     }
 }
예제 #19
0
        public MembershipUser CreateUser(string username, string password, string email)
        {
            using (KlmsnContext db = new KlmsnContext())
            {
                User user = new User();

                user.UserName          = username;
                user.Email             = email;
                user.PasswordSalt      = CreateSalt();
                user.Password          = CreatePasswordHash(password, user.PasswordSalt);
                user.CreatedDate       = DateTime.Now;
                user.IsActivated       = false;
                user.IsLockedOut       = false;
                user.LastLockedOutDate = DateTime.Now;
                user.LastLoginDate     = DateTime.Now;

                db.Users.Add(user);
                db.SaveChanges();

                return(GetUser(username));
            }
        }
예제 #20
0
        public MembershipUser GetUser(string username)
        {
            using (KlmsnContext db = new KlmsnContext())
            {
                var result = from u in db.Users where (u.UserName == username) select u;

                if (result.Count() != 0)
                {
                    var dbuser = result.FirstOrDefault();

                    string _username = dbuser.UserName;
                    int _providerUserKey = dbuser.UserId;
                    string _email = dbuser.Email;
                    string _passwordQuestion = "";
                    string _comment = dbuser.Comments;
                    bool _isApproved = dbuser.IsActivated;
                    bool _isLockedOut = dbuser.IsLockedOut;
                    DateTime _creationDate = dbuser.CreatedDate;
                    DateTime _lastLoginDate = dbuser.LastLoginDate.GetValueOrDefault(DateTime.Now);
                    DateTime _lastActivityDate = DateTime.Now;
                    DateTime _lastPasswordChangedDate = DateTime.Now;
                    DateTime _lastLockedOutDate = dbuser.LastLockedOutDate.GetValueOrDefault(DateTime.Now);

                    MembershipUser user = new MembershipUser("CustomMembershipProvider",
                                                              _username,
                                                              _providerUserKey,
                                                              _email,
                                                              _passwordQuestion,
                                                              _comment,
                                                              _isApproved,
                                                              _isLockedOut,
                                                              _creationDate,
                                                              _lastLoginDate,
                                                              _lastActivityDate,
                                                              _lastPasswordChangedDate,
                                                              _lastLockedOutDate
                                                              );

                    return user;
                }
                else
                {
                    return null;
                }
            }
        }
예제 #21
0
        public ActionResult Edit(SurveyTemplate surveytemplate, FormCollection formcollection)
        {
            if (ModelState.IsValid)
            {
                if (db.SurveyTemplates.AsNoTracking().Where(i => i.RequestTypeID == surveytemplate.RequestTypeID && i.PreDefined == true && i.SurveyTemplateID != surveytemplate.SurveyTemplateID).ToList().Count > 0)
                {
                    ViewBag.CustomErr = "İlgili İş tipine ait bir taslak zaten var. Lütfen Başka Bir Tip seçiniz";
                    return RedirectToAction("Edit", new { id = surveytemplate.SurveyTemplateID });
                }

                db.Entry(surveytemplate).State = EntityState.Modified;
                db.SaveChanges();
                SurveyTemplate mysurvtemplate_ = db.SurveyTemplates.Include(p => p.SurveyRecords).Where(i => i.SurveyTemplateID == surveytemplate.SurveyTemplateID).SingleOrDefault();
                int xindex = 0;
                foreach (SurveyNode snode_ in db.SurveyNodes.ToList())
                {
                    try
                    {
                        if (bool.Parse(formcollection[snode_.SurveyNodeID.ToString() + "_Remove"].Split(',')[0]))
                        {
                        }
                        else
                        {
                            SurveyRecord mysurvrec = db.SurveyTemplates.AsNoTracking().Where(i => i.SurveyTemplateID == surveytemplate.SurveyTemplateID).SingleOrDefault().SurveyRecords.Where(u => u.SurveyNodeID == snode_.SurveyNodeID).SingleOrDefault();
                            var mysrec = db.SurveyRecords.Find(mysurvrec.SurveyRecordID);
                            surveytemplate.SurveyRecords.Remove(mysrec);
                            db.Entry(surveytemplate).State = EntityState.Modified;

                            //db.SurveyRecords.Remove(mysurvrec);
                            db.SaveChanges();
                            KlmsnContext db_ = new KlmsnContext();
                            var mysrec_forremove = db_.SurveyRecords.Find(mysurvrec.SurveyRecordID);
                            db_.SurveyRecords.Remove(mysrec_forremove);
                            db_.SaveChanges();
                            db_.Dispose();
                            try
                            {
                                if (bool.Parse(formcollection[snode_.SurveyNodeID.ToString() + "_Check"].Split(',')[0]))
                                {
                                    SurveyRecord newsurvrec = new SurveyRecord { SurveyNodeID = snode_.SurveyNodeID, OrderNum = xindex, SurveyRecordTypeID = int.Parse(formcollection[snode_.SurveyNodeID.ToString() + "_survrectype"]) };
                                    mysurvtemplate_.SurveyRecords.Add(newsurvrec);
                                    db.SaveChanges();
                                    xindex++;
                                }
                            }
                            catch (Exception ex)
                            {
                                ViewBag.CustomErr = ex.Message;
                            }
                        }
                    }
                    catch
                    {
                        try
                        {
                            if (bool.Parse(formcollection[snode_.SurveyNodeID.ToString() + "_Check"].Split(',')[0]))
                            {
                                SurveyRecord newsurvrec = new SurveyRecord { SurveyNodeID = snode_.SurveyNodeID, OrderNum = xindex, SurveyRecordTypeID = int.Parse(formcollection[snode_.SurveyNodeID.ToString() + "_survrectype"]) };
                                mysurvtemplate_.SurveyRecords.Add(newsurvrec);
                                db.SaveChanges();
                                xindex++;
                            }
                        }
                        catch (Exception ex)
                        {
                            ViewBag.CustomErr = ex.Message;
                        }
                    }
                    xindex++;
                }

                return RedirectToAction("Index");
            }

            ViewBag.AllSurveyNodes = db.SurveyNodes.ToList();
            ViewBag.TheseSurveyRecords = db.SurveyTemplates.Find(surveytemplate.SurveyTemplateID).SurveyRecords.ToList();
            ViewBag.RequestTypeID = new SelectList(db.RequestTypes, "RequestTypeID", "Description", surveytemplate.RequestTypeID);
            return View(surveytemplate);
        }
예제 #22
0
        public bool HasModuleAccess(string username, int moduleId)
        {
            using (KlmsnContext db = new KlmsnContext())
            {
                try
                {
                    var result = (from u in db.Users where (u.UserName == username) select u).FirstOrDefault();
                    int xsay = result.Modules.Where(i => i.ModuleID == moduleId).Count();

                    if (xsay > 0)
                    {
                        return true;
                    }
                }
                catch { return false; }
            }
            return false;
        }
예제 #23
0
        public string GetUserNameByEmail(string email)
        {
            using (KlmsnContext db = new KlmsnContext())
            {
                var result = from u in db.Users where (u.Email == email) select u;

                if (result.Count() != 0)
                {
                    var dbuser = result.FirstOrDefault();

                    return dbuser.UserName;
                }
                else
                {
                    return "";
                }
            }
        }
예제 #24
0
        public bool HasPerm(int userID, string customPerm)
        {
            using (KlmsnContext db = new KlmsnContext())
            {
                //kendisinin var mi?
                var user_ = db.Users.Find(userID);
                var user_perms = user_.CustomPermissions.ToList();
                var usergroups_ = user_.UserGroups.ToList();
                foreach (UserGroup group_ in usergroups_)
                {
                    foreach (CustomPermission cp_ in group_.CustomPermissions.ToList())
                    {
                        user_perms.Add(cp_);
                    }
                }

                db.Dispose();
                foreach(CustomPermission cp in user_perms)
                {
                    if (cp.Description.Equals(customPerm))
                    {
                        return true;
                    }
                }

                //gruplarinin var mi?

                return false;
            }
        }
예제 #25
0
        public bool isInRole(int userID, string roleName)
        {
            using (KlmsnContext db = new KlmsnContext())
            {
                var user_ = db.Users.Find(userID);

                var user_roles = user_.Roles.ToList();
                db.Dispose();
                foreach (Role rl in user_roles)
                {
                    if (rl.Description.ToLower() == roleName.ToLower())
                        return true;
                }
                return false;
            }
        }
예제 #26
0
 public string resetPass(string userName)
 {
     using (KlmsnContext db = new KlmsnContext())
     {
         try
         {
             User user = db.Users.Where(i => i.UserName == userName).SingleOrDefault();
             user.PasswordSalt = CreateSalt();
             user.Password = CreatePasswordHash("123456", user.PasswordSalt);
             db.SaveChanges();
             db.Dispose();
             return "123456";
         }
         catch
         {
             return "Şifre Sıfırlamada Hata";
         }
     }
 }
예제 #27
0
        public bool ValidateUser(string username, string password)
        {
            using (KlmsnContext db = new KlmsnContext())
            {
                var result = from u in db.Users where (u.UserName == username) select u;

                if (result.Count() != 0)
                {
                    var dbuser = result.First();

                    if (dbuser.Password == CreatePasswordHash(password, dbuser.PasswordSalt))
                        return true;
                    else
                        return false;
                }
                else
                {
                    return false;
                }
            }
        }
예제 #28
0
        public IList<Role> GetRoles(string username)
        {
            using (KlmsnContext db = new KlmsnContext())
            {
                var result = from u in db.Users where (u.UserName == username) select u;

                if (result.Count() != 0)
                {
                    var dbuser = result.FirstOrDefault();

                    return dbuser.Roles.ToList();
                }
                else
                {
                    return null;
                }
            }
        }