Example #1
0
        public void AddNewUser(string firstname, string surname, string email, string description, string username, string password, byte[] imagebyte, string imgtype)
        {
            using (ObjectContext context = new ObjectContext(_connectionString))
            {
                var users = context.CreateObjectSet<User>();
                int maxId = users.Any() ? users.Max(x => x.Id) : 1;

                int pictureId = _pictureRepository.AddPicture(imagebyte, imgtype, string.Empty);

                User newUser = new User()
                {
                    Id = +maxId,
                    Firstname = firstname,
                    Surname = surname,
                    Email = email,
                    DateRegister = DateTime.Now,
                    Description = description,
                    Username = username,
                    Password = password,
                    isEnable = true,
                    isAdmin = false,
                    PictureId = pictureId
                };

                users.AddObject(newUser);
                context.SaveChanges();
            };
        }
Example #2
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Session[SessionKeys.USER_INFO] != null)
     {
         _user = (User)Session[SessionKeys.USER_INFO];
     }
     else
     {
         Response.Redirect("~/Default.aspx");
     }
     FillTable(_user);
     this.Master.TitleText = "Personal info about " + _user.Username;
 }
Example #3
0
        private void FillTable(User user)
        {
            CreateTableRow("UserId", user.Id);

            string strFullName = String.Format("{0} {1}", user.Surname, user.Firstname);
            CreateTableRow("Fullname", strFullName);

            CreateTableRow("UserName", user.Username);

            CreateTableRow("Email", user.Email);

            CreateTableRow("Date Registration", user.DateRegister);

            CreateTableRow("isEnable", user.isEnable);

            CreateTableRow("Date Disable", user.DateDisable);

            CreateTableRow("Password", user.Password);

            CreateTableRow("isAdmin", user.isAdmin);

               Picture picture = _pictureRepository.GetPicture(user.PictureId);

            CreateTableRow("Image", picture.FileData);

            CreateTableRow("ImageType", picture.ImageMimeType);
        }
        private ClaimsPrincipal CreatePrincipal(User user)
        {
            string userName = user.Username;
            List<string> roles = new List<string>();
            roles.Add("user");
            if (user.isAdmin)
            {
                roles.Add("admin");
            }
            GenericIdentity identity = new GenericIdentity(user.Username);
            GenericPrincipal principal = new GenericPrincipal(identity, roles.ToArray());

            return principal;
        }