コード例 #1
0
        public bool Register(string fname, string lname, string email, string password)
        {
            using (var work = new UnitOfWork())
            {
                if (work.Users.GetAll().FirstOrDefault(x => x.Email == email) != null)
                {
                    Logger.Error(string.Format(Resources.LogRegisterExistingEmail, email));
                    return false;
                }

                var hash = new Md5CryptoService();

                ProfilePhoto photo = (new UsersPhotoService()).GetRandomPhoto();
                var user = new User(fname, lname, email, password, photo)
                {
                    HashPassword = hash.CalculateMd5Hash(password),
                    LocationId = work.Locations.GetAll().First().Id,
                    UserName = email,
                    Birthdate = DateTime.Now
                };

                work.Users.Create(user);
                work.Save();
                List<User> users = work.Users.GetAll().ToList();
                Logger.Info(string.Format(Resources.RegistrationFinished, email));

                return true;
            }
        }
コード例 #2
0
        public static async Task<IdentityResult> Registration(SocialNetwork.Domain.DataTransferObjects.RegistrationDTO model)
        {
            using (var work = new UnitOfWork())
            {
                List<Role> roles = new List<Role>();
                roles.Add(work.Roles.FindByNameAsync("User").Result);

                ProfilePhoto photo = (new UsersPhotoService()).GetRandomPhoto();
                var user = new User(model.FirstName, model.LastName, model.Email, photo)
                {
                    LocationId = work.Locations.GetAll().First().Id,
                    UserName = model.UserName,
                    Birthdate = DateTime.Now,
                    Roles = roles
                };

                try
                {
                    IdentityUserManager userManager = new IdentityUserManager(work.Users);
                    var res = await userManager.CreateAsync(user, model.Password);
                    work.Save();
                    return res;
                }
                catch (Exception)
                {                    
                    return null;
                }
            }
        }
コード例 #3
0
        public bool DeleteProfile(Guid id)
        {
            using (var work = new UnitOfWork())
            {
                work.Users.Delete(id);
                work.Save();

                Logger.Info(string.Format(Resources.ProfileDeleted, id));

                return true;
            }
        }
コード例 #4
0
        public void CreatePhoto(Guid id, string url)
        {
            using (UnitOfWork work = new UnitOfWork())
            {
                work.ProfilePhotos.Create(new Domain.Entities.ProfilePhoto
                {
                    Id = id,
                    Url = url
                });

                work.Save();
            }
        }
コード例 #5
0
        /// <summary>
        /// Adding friend to user
        /// </summary>
        /// <param name="userId1">first user of friend connections</param>
        /// <param name="userId2">second user of friend connection</param>
        public void AddToFriends(Guid userId1, Guid userId2)
        {
            using (var work = new UnitOfWork())
            {
                work.Connections.Create(
                    new Connection
                    {
                        User1Id = userId1,
                        User2Id = userId2
                    });

                work.Save();
            }
        }
コード例 #6
0
        //// private readonly IPathProvider pathProvider;
        //// public ImageService(IPathProvider pathProvider)
        //// {
        ////    this.pathProvider = pathProvider;
        //// }
        public ProfilePhoto Create(Guid photoId, Guid userId)
        {
            using (UnitOfWork work = new UnitOfWork())
            {
                ProfilePhoto image = work.ProfilePhotos.Get(photoId);
                var user = work.Users.Get(userId);
                if (user.ProfilePhotoId != null && work.ProfilePhotos.Get(user.ProfilePhotoId) != null)
                {
                    DeletePhoto(user.ProfilePhotoId);
                }

                user.ProfilePhotoId = image.Id;
                work.Save();

                return image;
            }
        }