コード例 #1
0
        public ActionResult EditUser(int userID)
        {
            int userid = Convert.ToInt32(userID);

            using (var db = new DataModelContext())
            {
                tbl_users users = db.tbl_users.Find(userid);

                //DropdownList for user Types
                var userTypes = db.tbl_userType.ToList();
                List<SelectListItem> dropdownUserTypes = new List<SelectListItem>();
                SelectList list = new SelectList(userTypes);

                foreach (var item in userTypes)
                {

                    dropdownUserTypes.Add(new SelectListItem{ Text=item.typeName, Value=item.typeID.ToString() });

                }

                //------

                if (users == null)
                {
                    return HttpNotFound();

                }
                ViewBag.UserTypeList = new SelectList(userTypes, "typeID", "typeName");
                return PartialView(users);
            }
        }
コード例 #2
0
ファイル: AccountHelper.cs プロジェクト: kutlueren/Management
 public tbl_userType getRole(string RoleName)
 {
     using(var db=new DataModelContext())
     {
         tbl_userType role = db.tbl_userType.SingleOrDefault(u => u.typeName == RoleName);
         return role;
     }
 }
コード例 #3
0
ファイル: AccountHelper.cs プロジェクト: kutlueren/Management
        public IQueryable<tbl_users> getAllUser()
        {
            var db = new DataModelContext();

                return from u in db.tbl_users
                           orderby u.userID
                           select u;
        }
コード例 #4
0
ファイル: AccountHelper.cs プロジェクト: kutlueren/Management
        public tbl_users getUsers(string username)
        {
            using(var db=new DataModelContext())
            {

                tbl_users user = db.tbl_users.SingleOrDefault(u => u.userName == username);
                return user;
            }
        }
コード例 #5
0
ファイル: AccountHelper.cs プロジェクト: kutlueren/Management
        public void createNewUser(string username, string password, string email, byte RoleID)
        {
            tbl_users usersModel = new tbl_users();

            using (var db = new DataModelContext())
            {

                usersModel.userName = username;
                usersModel.password = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "md5");
                usersModel.email = email;
                usersModel.typeID = RoleID; // Default User Type

                db.tbl_users.Add(usersModel);
                db.SaveChanges();

            }
        }
コード例 #6
0
        // Delete Role
        public ActionResult DeleteRole(Byte typeID)
        {
            using (var db = new DataModelContext())
            {

                tbl_userType type = db.tbl_userType.Find(typeID);

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

                db.tbl_userType.Remove(type);
                db.SaveChanges();

                return RedirectToAction("Roles");

            }
        }
コード例 #7
0
        public override string[] GetRolesForUser(string username)
        {
            using (var db = new DataModelContext())
            {
                tbl_users user = db.tbl_users.SingleOrDefault(u => u.userName == username);
                if (user == null)
                {

                    return new string[] { string.Empty };

                }

                tbl_userType role = db.tbl_userType.SingleOrDefault(u => u.typeID == user.typeID);
                if (role == null)
                {
                    return new string[] { string.Empty };
                }

                return new string[] { role.typeName.Trim() };

            }
        }
コード例 #8
0
        public ActionResult UploadImage(UploadModel upload)
        {
            if (ModelState.IsValid)
            {
                Bitmap original = null;
                var name = "newimagefile";
                var errorField = string.Empty;
                string foldername = "default";

                if (upload.IsUrl)
                {
                    errorField = "Url";
                    name = GetUrlFileName(upload.Url);
                    original = GetImageFromUrl(upload.Url);
                }
                else if (upload.IsFlickr)
                {
                    errorField = "Flickr";
                    name = GetUrlFileName(upload.Flickr);
                    original = GetImageFromUrl(upload.Flickr);
                }
                else if (upload.File != null) // model.IsFile
                {
                    errorField = "File";
                    name = Path.GetFileNameWithoutExtension(upload.File.FileName);
                    original = Bitmap.FromStream(upload.File.InputStream) as Bitmap;

                     foldername = Server.MapPath("~/Content/images/Profile/"+upload.userID.ToString());  // Create Directory /userID
                     DirectoryInfo directory = new DirectoryInfo(foldername);
                     if (!Directory.Exists(foldername))
                    {
                        directory.Create();
                    }

                }

                // User Find And Update
                using (var db = new DataModelContext())
                {

                    tbl_userProfile userprofile = db.tbl_userProfile.Find(upload.userID);
                    if (userprofile != null)
                    {
                        userprofile.image = name;
                        db.Entry(userprofile).State = EntityState.Modified;
                        db.SaveChanges();

                    }

                }

                //If we had success so far
                if (original != null)
                {
                    var img = CreateImage(original, upload.X, upload.Y, upload.Width, upload.Height);

                    //Demo purposes only - save image in the file system
                    var fn = Server.MapPath(foldername+"\\profile"+".png");
                    img.Save(fn, System.Drawing.Imaging.ImageFormat.Png);

                    //Redirect to index
                    return RedirectToAction("Index");

                }

            }

            return View(upload);
        }
コード例 #9
0
 // User Profile List
 public ActionResult userProfileList()
 {
     using (var db =new DataModelContext())
     {
         var profileList = db.tbl_userProfile.ToList();
         return View(profileList);
     }
 }
コード例 #10
0
        public ActionResult UsersList()
        {
            var db = new DataModelContext();
            var users = db.tbl_users.ToList();

                return View(users);
        }
コード例 #11
0
        public ActionResult userProfile(tbl_userProfile userprofile)
        {
            if (ModelState.IsValid)
            {
                using (var db = new DataModelContext())
                {

                    tbl_userProfile userprof = (from profile in db.tbl_userProfile where profile.userID == userprofile.userID select profile).FirstOrDefault();

                    if (userprof == null)// user not found in database, insert new data
                    {
                        userprofile.createDate = DateTime.Now;
                        db.tbl_userProfile.Add(userprofile);
                        db.SaveChanges();
                        return RedirectToAction("UsersList");
                    }
                    else   // already has user data Update !
                    {

                        userprof.nameSurname = userprofile.nameSurname;
                        userprof.phone = userprofile.phone;
                        userprof.adress = userprofile.adress;

                        userprof.createDate = DateTime.Now;
                        db.Entry(userprof).State = EntityState.Modified;
                        db.SaveChanges();
                        return RedirectToAction("UsersList");
                    }
                }

            }
            else
            {
                ModelState.AddModelError("ProfileAdd", "Do not new user profile!..");
            }

            return View(userprofile);
        }
コード例 #12
0
        // Find userProfiles
        public ActionResult userProfileEdit(int userID)
        {
            if (userID == 0)
            {
                return HttpNotFound();
            }
            else
            {
                using (var db = new DataModelContext())
                {
                    var userinfo = db.tbl_userProfile.Find(userID);
                    if (userinfo == null)
                    {
                        ModelState.AddModelError("UserProfile", "User not found..!");
                    }
                    else
                    {
                        return RedirectToAction("UserList");
                    }

                    return View(userinfo);
                }

            }
        }
コード例 #13
0
        // Start
        public ActionResult userProfile(int userID)
        {
            if (userID == 0)
            {
                ModelState.AddModelError("UserInfo", "UserID is not empty!");
                return RedirectToAction("UsersList");
            }
            else
            {
                ViewBag.UserId = userID;
                using (var db = new DataModelContext())
                {

                    tbl_userProfile userprof = (from profile in db.tbl_userProfile where profile.userID == userID select profile).FirstOrDefault();

                    return View(userprof);
                }

            }
        }
コード例 #14
0
        public ActionResult UserDeleteConfirmed(int userID)
        {
            using (var db = new DataModelContext())
            {

               tbl_users users = db.tbl_users.Find(userID);
               if (users == null)
               {
                   return HttpNotFound();
               }
               else
               {

                   db.tbl_users.Remove(users);
                   db.SaveChanges();
               }
            }
            return RedirectToAction("UsersList");
        }
コード例 #15
0
        public ActionResult EditUser(tbl_users user)
        {
            if (ModelState.IsValid)
            {
                using (var db = new DataModelContext())
                {
                    user.typeID = Convert.ToByte(user.typeID);

                    //Utility cryptor = new Utility();  // Encrypt User Password
                    //string encrypt = cryptor.CreatePasswordHash(user.password, user.saltPass = cryptor.GenerateSalt(58), "SHA1");
                    string encrypt = FormsAuthentication.HashPasswordForStoringInConfigFile(user.password, "md5");
                    user.password = encrypt;

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

                    return RedirectToAction("UsersList");
                }

            }
            else
            {
                return RedirectToAction("EditUser");
            }
        }
コード例 #16
0
        public ActionResult Roles()
        {
            using (var db = new DataModelContext())
            {
                var userTypes = db.tbl_userType.ToList();

                if (userTypes == null)
                {
                    ModelState.AddModelError("Role List Error", "Role List is null");
                    return RedirectToAction("Index");
                }

                return View(userTypes);

            }
        }
コード例 #17
0
        public ActionResult Roles(tbl_userType usertype)
        {
            if (ModelState.IsValid)
            {

                var db = new DataModelContext();

                    db.tbl_userType.Add(usertype);
                    db.SaveChanges();
                    return RedirectToAction("Roles");

            }

            return View();
        }
コード例 #18
0
        // User Login Control
        public int UserIsValid(string username, string password)
        {
            //  Utility cryptor = new Utility();

            using (var db = new DataModelContext())
            {
                try
                {
                    var salt = db.tbl_users.Single(m => m.userName == username);
                   // string encrypted = cryptor.CreatePasswordHash(password, salt.saltPass, "SHA1");
                    string encrypted = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "md5");
                    int loggedUserID = db.spLogIn(username, password);
                    return loggedUserID;

                }
                catch (Exception)
                {
                    ModelState.AddModelError("DataError", "User not found!");
                    return -1;
                }

            }
        }
コード例 #19
0
        public ActionResult UserDelete(int userID)
        {
            using (var db = new DataModelContext())
            {

                tbl_users users = db.tbl_users.Find(userID);
                if (users == null)
                {
                   return HttpNotFound();
                }

                return View(users);
            }
        }