public ActionResult Create([Bind(Exclude = "ProfileImage")] ProfileModels profile)
        {
            // Excludes ProfileImage from controller call so it doesn't crash.
            if (ModelState.IsValid)
            {
                // Convert the uploaded photo to a byte array that we can store in the database.
                byte[] imageData = null;
                if (Request.Files["ProfileImage"].ContentLength >= 1)   // Check if a file is entered
                {
                    HttpPostedFileBase poImgFile = Request.Files["ProfileImage"];

                    using (var binary = new BinaryReader(poImgFile.InputStream)) {
                        //This is the byte-array we set as the ProfileImage property on the profile.
                        imageData = binary.ReadBytes(poImgFile.ContentLength);
                    }
                }
                else     // If they did not submit a profile image they get the default avatar
                {
                    string     path = AppDomain.CurrentDomain.BaseDirectory + "/Content/Images/defaultAvatar.png";
                    FileStream file = new FileStream(path, FileMode.Open);

                    using (var binary = new BinaryReader(file)) {
                        imageData = binary.ReadBytes((int)file.Length);
                    }
                }

                profile.Id           = User.Identity.GetUserId();
                profile.ProfileImage = imageData;
                profile.IsActive     = true;
                profileRepository.Add(profile);
                profileRepository.Save();
                return(RedirectToAction("Index"));
            }
            return(RedirectToAction("Create"));
        }
Beispiel #2
0
        public async void Test_GenericRepository_Find()
        {
            var options = new DbContextOptionsBuilder <AccountContext>()
                          .UseInMemoryDatabase(databaseName: "Test1G")
                          .Options;

            using (var ctx = new AccountContext(options))
            {
                var profiles   = new ProfileRepository(ctx);
                var newProfile = new ProfileModel()
                {
                    Id        = 10,
                    Email     = "*****@*****.**",
                    Name      = null,
                    Phone     = "1234567897",
                    Age       = "Adult",
                    AccountId = 1,
                    Account   = null
                };
                await profiles.Add(newProfile);

                await ctx.SaveChangesAsync();

                var actual = await profiles.Find(profile => profile.AccountId == 1);

                var phone = actual.First().Phone;

                Assert.Equal("1234567897", phone);
            }
        }
Beispiel #3
0
        public ActionResult RegisterNow(AppUserVM apvm)
        {
            AppUser     appUser = apvm.AppUser;
            UserProfile profile = apvm.UserProfile;

            appUser.Password = DantexCrypt.Crypt(appUser.Password); //sifreyi kriptoladık

            //AppUser.Password = DantexCrypt.DeCrypt(apvm.AppUser.Password);

            if (apRep.Any(x => x.UserName == appUser.UserName))
            {
                ViewBag.ZatenVar = "Kullanıcı ismi daha önce alınmıs";
                return(View());
            }
            else if (apRep.Any(x => x.Email == appUser.Email))
            {
                ViewBag.ZatenVar = "Email zaten kayıtlı";
                return(View());
            }

            //Kullanıcı basarılı bir şekilde register işlemini tamamladıysa ona mail gönder

            string gonderilecekMail = "Tebrikler...Hesabınız olusturulmustur. Hesabınızı aktive etmek icin https://localhost:44389/Register/Activation/" + appUser.ActivationCode + " linkine tıklayabilirsiniz.";

            MailSender.Send(appUser.Email, body: gonderilecekMail, subject: "Hesap aktivasyon!");
            apRep.Add(appUser); //öncelikle bunu eklemelisiniz. Cnkü AppUser'in ID'si ilk basta olusmalı... Cünkü biz birebir ilişkide AppUser zorunlu alan Profile ise opsiyonel alandır. Dolayısıyla ilk basta AppUser'in ID'si SaveChanges ile olusmalı ki sonra Profile'i rahatca ekleyebilelim...

            if (!string.IsNullOrEmpty(profile.FirstName) || !string.IsNullOrEmpty(profile.LastName) || !string.IsNullOrEmpty(profile.Address))
            {
                profile.ID = appUser.ID;
                apdRep.Add(profile);
            }

            return(View("RegisterOk"));
        }
Beispiel #4
0
        public IProfile Add(ProfileCreationArgs profileCreationArgs)
        {
            ProfileDomainObject newProfile = ProfileRepository.Add(profileCreationArgs, _accountName);

            Profiles.Add(newProfile.Name, newProfile);
            RaiseProfileCollectionChanged();
            return(newProfile);
        }
Beispiel #5
0
        public ProfileMutation(ProfileRepository profileRepository)
        {
            /**
             * NEW PROFILE
             */
            Field <ProfileType, Profile>()
            .Name("createProfile")
            .Argument <NonNullGraphType <ProfileInputType> >("profile", "profile input")
            .ResolveAsync(async ctx =>
            {
                var profile = ctx.GetArgument <Profile>("profile");
                return(await profileRepository.Add(profile));
            });

            /**
             * UPDATE PROFILE
             */
            Field <ProfileType, Profile>()
            .Name("updateProfile")
            .Argument <NonNullGraphType <ProfileInputType> >("profile", "profile input")
            .ResolveAsync(async ctx =>
            {
                var profile = ctx.GetArgument <Profile>("profile");

                // Check if profile exists
                var currentProfile = await profileRepository.FindById(profile.Id);
                if (currentProfile == null)
                {
                    ctx.Errors.Add(new ExecutionError("Profile not found"));
                    return(null);
                }
                // Update profile
                return(await profileRepository.Update(profile));
            });

            /**
             * DELETE PROFILE
             */
            Field <ProfileType, Profile>()
            .Name("deleteProfile")
            .Argument <NonNullGraphType <IdGraphType> >("id", "profile id input")
            .ResolveAsync(async ctx =>
            {
                var id = ctx.GetArgument <int>("id");

                // Check if profile exists
                var currentProfile = await profileRepository.FindById(id);
                if (currentProfile == null)
                {
                    ctx.Errors.Add(new ExecutionError("Profile not found"));
                    return(null);
                }
                // delete profile
                await profileRepository.Remove(id);

                return(null);
            });
        }
Beispiel #6
0
 //Add profile
 public UserProfile Add(UserProfile profile)
 {
     try
     {
         return(_profileRepository.Add(profile));
     }
     catch (Exception e)
     {
         throw new Exception("Error - Add the user's profile.");
     }
 }
 //Add profile
 public Profile Add(Profile profile)
 {
     try
     {
         return(_profileRepository.Add(profile));
     }
     catch (Exception e)
     {
         //Log Error
         throw new Exception("An error occurred while trying to add the user's profile.");
     }
 }
Beispiel #8
0
        public async void Test_GenericRepository_Update()
        {
            var options = new DbContextOptionsBuilder <AccountContext>()
                          .UseInMemoryDatabase(databaseName: "Test2G")
                          .Options;

            using (var ctx = new AccountContext(options))
            {
                var profiles   = new ProfileRepository(ctx);
                var payment    = new PaymentRepository(ctx);
                var newProfile = new ProfileModel()
                {
                    Id        = 0,
                    Email     = "*****@*****.**",
                    Name      = null,
                    Phone     = "1234567897",
                    Age       = "Adult",
                    AccountId = 1,
                    Account   = null
                };
                var updateProfile = new ProfileModel()
                {
                    Id        = 1,
                    Email     = "*****@*****.**",
                    Name      = null,
                    Phone     = "2222222222",
                    Age       = "Child",
                    AccountId = 1,
                    Account   = null
                };
                await profiles.Add(newProfile);

                await ctx.SaveChangesAsync();

                ctx.Entry <ProfileModel>(newProfile).State = EntityState.Detached;
                await profiles.Update(updateProfile);

                await ctx.SaveChangesAsync();

                var actual = await profiles.GetAll();

                var payments = await payment.GetAll();

                var payments2 = await payment.Find(payment => payment.AccountId == 1);

                var phone = actual.First().Phone;

                Assert.Equal("2222222222", phone);
                Assert.Empty(payments);
                Assert.Empty(payments2);
            }
        }
        /// <summary>
        /// Save profile
        /// </summary>
        /// <param name="profile"></param>
        /// <returns></returns>
        private Profile SaveProfile(Profile profile)
        {
            IEntityValidator entityValidator = EntityValidatorFactory.CreateValidator();

            if (entityValidator.IsValid(profile))
            {
                _profileRepository.Add(profile);
                _profileRepository.UnitOfWork.Commit();

                return(profile);
            }

            throw new ApplicationValidationErrorsException(entityValidator.GetInvalidMessages(profile));
        }
Beispiel #10
0
        public void AddProfile(ProfileDTO profiledto, string username)
        {
            var user    = _repo.GetUserByUsername(username);
            var profile = new Profile
            {
                Id       = profiledto.Id,
                DOB      = profiledto.DOB,
                Faction  = profiledto.Faction,
                Location = profiledto.Location,
                Name     = profiledto.Name
            };

            _repo.Add(profile);
            _repo.SaveChanges();
        }
Beispiel #11
0
        public void Add_Get_Delete_ItemTest()
        {
            ProfileRepository repo = new ProfileRepository();
            Profile           pro  = new Profile {
                UserName = "******", ProfileName = "hello1", Password = "******", Email = "*****@*****.**"
            };

            //add
            repo.Add(pro);
            var temp = repo.Get(pro.UserName);

            Assert.IsNotNull(temp);
            //remove
            repo.Remove(pro.UserName);
        }
Beispiel #12
0
        /// <summary>
        /// Save Profile
        /// </summary>
        /// <param name="profile"></param>
        Profile SaveProfile(Profile profile)
        {
            var entityValidator = EntityValidatorFactory.CreateValidator();

            if (entityValidator.IsValid(profile))//if entity is valid save.
            {
                //add profile and commit changes
                _profileRepository.Add(profile);
                _profileRepository.UnitOfWork.Commit();
                return(profile);
            }
            else // if not valid throw validation errors
            {
                throw new ApplicationValidationErrorsException(entityValidator.GetInvalidMessages(profile));
            }
        }
Beispiel #13
0
        private void BtnSave_Click(object sender, EventArgs e)
        {
            AppUser appUser = new AppUser();

            appUser.UserName = txtUserName.Text;
            appUser.Password = txtPassword.Text;
            appUser.Role     = (UserRole)cbRoles.SelectedItem;
            appUserRepository.Add(appUser);

            Profile profile = new Profile();

            profile.FirstName = txtFirstName.Text;
            profile.LastName  = txtLastName.Text;
            profile.AppUser   = appUser;
            profileRepository.Add(profile);

            ClearTextBoxes();
        }
Beispiel #14
0
        public void UpdateProfileTest()
        {
            ProfileRepository repo = new ProfileRepository();
            Profile           pro  = new Profile {
                UserName = "******", ProfileName = "hello1", Password = "******", Email = "*****@*****.**"
            };

            //add
            repo.Add(pro);
            //change value
            pro.Password = "******";
            var booll = repo.Update(pro);

            //check remove success
            Assert.AreEqual(true, booll);
            var temp = repo.Get(pro.UserName);

            Assert.AreEqual(pro.Password, temp.Password);
        }
Beispiel #15
0
        public Profile AddProfile(Profile newProfile)
        {
            var profile = newProfile;

            profile.JoinDate = DateTime.Now;
            profile.Age      = 26;
            //int.Parse((DateTime.Now - profile.DateOfBirth).TotalDays.ToString());
            profile.MembershipLevelID    = 4;
            profile.SubscriptionStatusID = 2;
            profile.Email = newProfile.Email;

            profile.Address         = "123";
            profile.MembershipLevel = new MembershipLevel
            {
                Level = "Non-member"
            };
            profile.SubscriptionStatus = new SubscriptionStatus
            {
                Status = "Inactive"
            };
            profiles.Add(profile);
            profiles.SaveChanges();
            return(profile);
        }
Beispiel #16
0
        public IProfile CreateAccount(AccountUser usuario)
        {
            IProfile result = new Profile();

            using (TransactionScope scope = new TransactionScope())
            {
                usuario.Created  = DateTime.Now;
                usuario.City     = Security.ClearSQLInjection(usuario.City);
                usuario.Country  = Security.ClearSQLInjection(usuario.Country);
                usuario.CustomId = Security.ClearSQLInjection(usuario.CustomId);
                usuario.Email    = Security.ClearSQLInjection(usuario.Email);
                usuario.Name     = Security.ClearSQLInjection(usuario.Name);
                usuario.Password = Security.ClearSQLInjection(usuario.Password);
                usuario.Picture  = Security.ClearSQLInjection(usuario.Picture);
                usuario.Gender   = Security.ClearSQLInjection(usuario.Gender);

                string emailcrypted = Security.Encrypt(usuario.Email);
                string passw        = PasswordHash.CreateHash(usuario.Password);

                usuario.Email    = emailcrypted;
                usuario.Password = passw;

                IUsuario iusuario = _repository.Add(usuario);

                ProfileRepository profile    = new ProfileRepository(_dataBase);
                IProfile          newProfile = new Profile();
                newProfile.UserId  = iusuario.UsuarioId;
                newProfile.Upadted = DateTime.Now;
                newProfile.Picture = Security.ClearSQLInjection(usuario.Picture);
                result             = profile.Add(newProfile);

                scope.Complete();
            }

            return(result);
        }
Beispiel #17
0
        public IProfile CreateAccount(AccountUser usuario)
        {
            IProfile result = new Profile();

            using (TransactionScope scope = new TransactionScope())
            {
                usuario.Created = DateTime.Now;
                usuario.City = Security.ClearSQLInjection(usuario.City);
                usuario.Country = Security.ClearSQLInjection(usuario.Country);
                usuario.CustomId = Security.ClearSQLInjection(usuario.CustomId);
                usuario.Email = Security.ClearSQLInjection(usuario.Email);
                usuario.Name = Security.ClearSQLInjection(usuario.Name);
                usuario.Password = Security.ClearSQLInjection(usuario.Password);
                usuario.Picture = Security.ClearSQLInjection(usuario.Picture);
                usuario.Gender = Security.ClearSQLInjection(usuario.Gender);

                string emailcrypted = Security.Encrypt(usuario.Email);
                string passw = PasswordHash.CreateHash(usuario.Password);

                usuario.Email = emailcrypted;
                usuario.Password = passw;

                IUsuario iusuario = _repository.Add(usuario);

                ProfileRepository profile = new ProfileRepository(_dataBase);
                IProfile newProfile = new Profile();
                newProfile.UserId = iusuario.UsuarioId;
                newProfile.Upadted = DateTime.Now;
                newProfile.Picture = Security.ClearSQLInjection(usuario.Picture);
                result = profile.Add(newProfile);

                scope.Complete();
            }

            return result;
        }
Beispiel #18
0
        /// <summary>
        /// Persist the specified <paramref name="profile"/> to the data store.
        /// </summary>
        /// <param name="profile">The profile to persist to the data store.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="profile" /> is null.</exception>
        public static void Save(IUserProfile profile)
        {
            if (profile == null)
            {
                throw new ArgumentNullException("profile");
            }

            using (var repo = new ProfileRepository())
            {
                // AlbumProfiles
                var pDto = (repo.Where(p => p.UserName == profile.UserName && p.SettingName == ProfileNameAlbumProfiles)).FirstOrDefault();

                var templateGalleryId = GetTemplateGalleryId();

                if (pDto == null)
                {
                    pDto = new UserGalleryProfileDto
                    {
                        UserName     = profile.UserName,
                        FKGalleryId  = templateGalleryId,
                        SettingName  = ProfileNameAlbumProfiles,
                        SettingValue = profile.AlbumProfiles.Serialize()
                    };

                    repo.Add(pDto);
                }
                else
                {
                    pDto.SettingValue = profile.AlbumProfiles.Serialize();
                }

                // Media Object Profiles
                pDto = (repo.Where(p => p.UserName == profile.UserName && p.SettingName == ProfileNameMediaObjectProfiles)).FirstOrDefault();

                if (pDto == null)
                {
                    pDto = new UserGalleryProfileDto
                    {
                        UserName     = profile.UserName,
                        FKGalleryId  = templateGalleryId,
                        SettingName  = ProfileNameMediaObjectProfiles,
                        SettingValue = profile.MediaObjectProfiles.Serialize()
                    };

                    repo.Add(pDto);
                }
                else
                {
                    pDto.SettingValue = profile.MediaObjectProfiles.Serialize();
                }

                // User Gallery Profiles
                foreach (IUserGalleryProfile userGalleryProfile in profile.GalleryProfiles)
                {
                    IUserGalleryProfile ugp = userGalleryProfile;

                    // EnableUserAlbum
                    pDto = (repo.Where(p => p.UserName == profile.UserName && p.FKGalleryId == ugp.GalleryId && p.SettingName == ProfileNameEnableUserAlbum)).FirstOrDefault();

                    if (pDto == null)
                    {
                        pDto = new UserGalleryProfileDto
                        {
                            UserName     = profile.UserName,
                            FKGalleryId  = ugp.GalleryId,
                            SettingName  = ProfileNameEnableUserAlbum,
                            SettingValue = ugp.EnableUserAlbum.ToString(CultureInfo.InvariantCulture)
                        };

                        repo.Add(pDto);
                    }
                    else
                    {
                        pDto.SettingValue = ugp.EnableUserAlbum.ToString(CultureInfo.InvariantCulture);
                    }

                    // UserAlbumId
                    pDto = (repo.Where(p => p.UserName == profile.UserName && p.FKGalleryId == ugp.GalleryId && p.SettingName == ProfileNameUserAlbumId)).FirstOrDefault();

                    if (pDto == null)
                    {
                        pDto = new UserGalleryProfileDto
                        {
                            UserName     = profile.UserName,
                            FKGalleryId  = ugp.GalleryId,
                            SettingName  = ProfileNameUserAlbumId,
                            SettingValue = ugp.UserAlbumId.ToString(CultureInfo.InvariantCulture)
                        };

                        repo.Add(pDto);
                    }
                    else
                    {
                        pDto.SettingValue = ugp.UserAlbumId.ToString(CultureInfo.InvariantCulture);
                    }
                }

                repo.Save();
            }
        }