public ActionResult UserSetting(int id) { User user; using (Models.Entidades.SocialNetworkEntities db = new SocialNetworkEntities()) { user = db.Users.Find(id); } string imreBase64Data = Convert.ToBase64String(user.profilepic); string imgDataURL = string.Format("data:image/png;base64,{0}", imreBase64Data); ViewBag.IMAGEN = imgDataURL; return(View(user)); }
public static void Main() { Database.SetInitializer(new MigrateDatabaseToLatestVersion <SocialNetworkEntities, Configuration>()); var dbContext = new SocialNetworkEntities(); dbContext.Database.CreateIfNotExists(); var importer = new XmlImporter(dbContext); importer.Import(); var service = new SocialNetworkService(dbContext); DataSearcher.Search(service); }
/// <summary> /// method for checking if the user with entered username and password exists /// </summary> /// <param name="username"></param> /// <param name="password"></param> /// <returns></returns> private bool IsUser(string username, string password) { try { using (SocialNetworkEntities context = new SocialNetworkEntities()) { tblUser user = (from x in context.tblUsers where x.Username == username && x.UserPassword == password select x).First(); return(true); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); return(false); } }
public ActionResult Register(UserEntity user) { MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider(); //create an array of bytes we will use to store the encrypted password Byte[] hashedBytes; //Create a UTF8Encoding object we will use to convert our password string to a byte array UTF8Encoding encoder = new UTF8Encoding(); hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(user.Password)); HttpPostedFileBase file = Request.Files["NewProfilePic"]; byte[] img; if (file.FileName == "") { img = null; } else { img = SocialNetwork.Services.MediaService.ConvertToBytes(file); } using (Models.Entidades.SocialNetworkEntities db = new SocialNetworkEntities()) { Models.Entidades.User usr = new User(); usr.profilepic = img; usr.password = hashedBytes; usr.name = user.Name; usr.lastname = user.Lastname; usr.username = user.Username; usr.email = user.Email; usr.birthdate = user.Birthdate; db.Users.Add(usr); db.SaveChanges(); } return(View()); }
/// <summary> /// method for adding new user /// </summary> private void SaveExecute() { try { using (SocialNetworkEntities context = new SocialNetworkEntities()) { tblUser newUser = new tblUser(); newUser.FirstName = user.FirstName; newUser.LastName = user.LastName; newUser.BirthDate = user.BirthDate; newUser.Username = user.Username; if (PasswordValidation(user.UserPassword)) { newUser.UserPassword = user.UserPassword; } else { MessageBox.Show("Wrong password. Password must have at least 8 characters.\n(1 upper char, 1 lower char, 1 number and 1 special char)\nPlease try again."); } newUser.UserID = user.UserID; context.tblUsers.Add(newUser); context.SaveChanges(); MessageBox.Show("The user created successfully."); } signUp.Close(); } catch (Exception) { MessageBox.Show("Wrong inputs, please check your inputs or try again."); } }
public SocialNetworkService(SocialNetworkEntities db) { this.context = db; }
public XmlImporter(SocialNetworkEntities db) { this.context = db; }