public async Task <IActionResult> Create([Bind("Name,Surname,Email,PhoneNumber,Password,ConfirmPassword,DateOfBirth,AccountType")] UserReadModel userReadModel)
        {
            if (ModelState.IsValid)
            {
                //password check here
                var passwordValid = userReadModel.Password == userReadModel.ConfirmPassword;
                if (passwordValid == true)
                {
                    var myUser = new User();
                    myUser.Name        = userReadModel.Name;
                    myUser.Surname     = userReadModel.Surname;
                    myUser.Email       = userReadModel.Email;
                    myUser.PhoneNumber = userReadModel.PhoneNumber;
                    myUser.Password    = userReadModel.Password;
                    myUser.DateOfBirth = userReadModel.DateOfBirth;
                    myUser.AccountType = userReadModel.AccountType;

                    _context.Add(myUser);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }

                else
                {
                    ModelState.Clear();
                    ModelState.AddModelError("ErrorMessage", "Passwords do not match! Try again.");
                    return(View());
                }
            }
            return(View());
        }
Exemple #2
0
        public async Task ReturnsCorrectUserMock(string user)
        {
            var expected = UserReadModel.MockContract();
            var actual   = await this.userApi.GetUserStatistics(user, TemplateMediaType.MockOutputFormatterJson); // ~38ms

            actual.Should().BeEquivalentTo(expected);
        }
Exemple #3
0
 public static UserDto ToDto(this UserReadModel model) => new UserDto()
 {
     UserId    = model.UserId,
     FirstName = model.FirstName,
     LastName  = model.LastName,
     RoleName  = model.RoleName,
     RoleId    = model.RoleId
 };
        public async Task Consume(ConsumeContext <ICalendarCreatedEvent> context)
        {
            var @event = context.Message;
            var user   = new UserReadModel();

            user            = _redisService.HashGet <UserReadModel>($"{user.RedisKey}", $"{@event.UserEmail}", CommandFlags.PreferMaster);
            user.CalendarId = @event.AggregateId;
            _redisService.HashSet($"{user.RedisKey}", $"{@event.UserEmail}", user, When.Always, CommandFlags.PreferMaster);
        }
 private async Task PublishEventAsync(
     UserReadModel user,
     CancellationToken cancellationToken)
 {
     await _publishEndpoint.Publish(
         new UserActivated(
             user.Phone,
             user.Email,
             user.LastName,
             user.FirstName), cancellationToken);
 }
Exemple #6
0
 private async Task PublishUserActivatedEventAsync(
     UserReadModel user,
     CancellationToken cancellationToken)
 {
     await _bus.Publish(
         new UserActivated(
             user.Phone,
             user.Email,
             user.LastName,
             user.FirstName,
             user.Id,
             user.SubjectId), cancellationToken);
 }
 private Task PublishEventAsync(
     UserReadModel model,
     DateTime expiryDateTimeUtc,
     CancellationToken cancellationToken)
 {
     return(_bus.Publish(
                new UserSubscriptionExtended(
                    model.FirstName,
                    model.LastName,
                    model.Email,
                    model.Phone,
                    expiryDateTimeUtc), cancellationToken));
 }
        public void Handle(UserCreatedEvent domainEvent)
        {
            var userReadModel = new UserReadModel
            {
                UserId            = domainEvent.UserId,
                UserName          = domainEvent.UserName,
                Password          = domainEvent.Password,
                Email             = domainEvent.Email,
                CanonicalUsername = domainEvent.UserName.ToLower()
            };

            db.AddToUserReadModels(userReadModel);
            db.SaveChanges();
        }
Exemple #9
0
        public async Task Handle(UserRegisteredEvent message)
        {
            var userReadModel = new UserReadModel
            {
                Id                 = message.Id,
                FirstName          = message.FirstName,
                LastName           = message.LastName,
                Email              = message.Email,
                IsAccountActivated = false
            };

            var session   = _mongoDbContext.Session;
            var readModel = _mongoDbContext.Database.GetCollection <UserReadModel>("userreadmodel");
            await readModel.InsertOneAsync(session, userReadModel);
        }
        public async Task Consume(ConsumeContext <IUserCreatedEvent> context)
        {
            var @event = context.Message;

            var user = new UserReadModel
            {
                Id          = @event.AggregateId,
                Version     = @event.Version,
                Email       = @event.Email,
                FamilyName  = @event.FamilyName,
                GivenName   = @event.GivenName,
                PhoneNumber = @event.PhoneNumber,
                Gender      = @event.Gender,
                Role        = @event.Role
            };

            _redisService.HashSet($"{user.RedisKey}", $"{user.Email}", user, When.Always, CommandFlags.PreferMaster);
        }
        public async Task Consume(ConsumeContext <IPetCreatedEvent> context)
        {
            var @event = context.Message;

            var user = new UserReadModel();

            user = _redisService.HashGet <UserReadModel>($"{user.RedisKey}", $"{@event.OwnerEmail}", CommandFlags.PreferMaster);
            user.Pets.Add(new PetReadModel
            {
                Id              = @event.AggregateId,
                Breed           = @event.Breed,
                Name            = @event.Name,
                ProfileImageUrl = @event.ProfileImageUrl,
                Sex             = @event.Sex,
                Species         = @event.Species
            });

            _redisService.HashSet($"{user.RedisKey}", $"{@event.OwnerEmail}", user, When.Always, CommandFlags.PreferMaster);
        }
        public IHttpActionResult GetCurrentUser()
        {
            // User is already authenticated and authorized for the read role.
            var userId           = _jwt.UserId;
            var allUserRoles     = _repo.GetAll();
            var currentUserRoles = allUserRoles.GetRolesFor(userId);

            var readModel = new UserReadModel
            {
                Scope      = _jwt.Scope,
                UserId     = userId,
                Name       = _jwt.Name,
                GivenName  = _jwt.GivenName,
                FamilyName = _jwt.FamilyName,
                Email      = _jwt.Email,
                Roles      = currentUserRoles.ToArray()
            };

            return(Ok(readModel));
        }
Exemple #13
0
        public async Task <IHttpActionResult> GetUserAsync(string userId)
        {
            var entity = await _usersRepository.Get(userId);

            var user = new UserReadModel
            {
                Id             = entity.Id,
                UserName       = entity.UserName,
                Email          = entity.Email,
                MessagesCount  = entity.MessageRecipients.Count,
                DonationsCount = 1500.24f,
                Messages       = entity.MessageRecipients.Select(x => new MessageReadModel
                {
                    Id      = x.Message.Id,
                    Subject = x.Message.Subject,
                    Content = x.Message.Content,
                    SentOn  = x.Message.SentOn.ToString("dd.MM.yyyy")
                }).ToList()
            };

            return(Ok(user));
        }
Exemple #14
0
 private static UserAccount UserAccoutFromReadModel(UserReadModel readModel) =>
 readModel
 ?.Map(x => new UserAccount(x.Username, x.PasswordHash));
Exemple #15
0
        public static void StartCommandLoop()
        {
            do //Command loop, runs until user shuts down program or EventStore
            {
                var cmd = Console.ReadLine();

                if (string.IsNullOrWhiteSpace(cmd))
                {
                    DisplayUserCommands();
                    continue;
                }

                string streamName = string.Empty;

                switch (cmd.ToLower())
                {
                case "exit":
                    Console.WriteLine("Disconnecting from EventStore");
                    EventStoreLoader.TeardownEventStore();
                    break;

                case "1t":
                    Console.Write("Please enter stream name (New or existing): ");
                    streamName = Console.ReadLine();
                    Console.WriteLine("Adding 3 events to stream " + streamName + "...\n");
                    CreateAndRunTestStream(streamName);
                    continue;

                case "2t":
                    Console.Write("Please enter existing stream name: ");
                    streamName = Console.ReadLine();
                    CreatePersistentSubscription(streamName);
                    Console.WriteLine("Persistent Subscription for stream \"" + streamName + "\" has been created!");
                    continue;

                case "3t":
                    Console.Write("Please enter existing stream name: ");
                    streamName = Console.ReadLine();
                    ConnectPersistentSubscription(streamName);
                    Console.WriteLine("Connection to Persistent Subscription for stream \"" + streamName + "\" has been created!");
                    Console.WriteLine("Waiting for new events...");
                    continue;

                case "4t":
                    Console.Write("Please enter stream name: ");
                    streamName = Console.ReadLine();
                    Console.Write("Read events reversed? (y/n): ");
                    string answer   = Console.ReadLine();
                    bool   reversed = answer == "y" ? true : false;
                    Console.WriteLine("Listing all events from stream...\n");
                    ListOperations(streamName, reversed);
                    continue;

                case "1d":
                    Console.Write("Please input username: "******"User with username \"" + userName + "\" has been saved to the Event Store!\n");
                    continue;

                case "2d":
                    Console.Write("Please input ID of user to update: ");
                    string userID = Console.ReadLine();
                    Console.Write("Please input new user name: ");
                    string userNameUpdated = Console.ReadLine();
                    userCommands.UpdateUserName(new Contracts.UpdateUserName()
                    {
                        UserId = Guid.Parse(userID), Name = userNameUpdated
                    });
                    Console.WriteLine("User " + userID + " has been updated with new username \"" + userNameUpdated + "\"");
                    continue;

                case "3d":
                    Console.WriteLine("Creating and connecting to Catch Up subscription for the $all stream...");
                    projectionManager.Start();
                    break;

                case "4d":
                    Console.Write("Please input ID of user to display: ");
                    string        userId      = Console.ReadLine();
                    UserReadModel queriedUser = userQueries.GetSingleUser(new UserQueryModels.GetUser()
                    {
                        UserId = Guid.Parse(userId)
                    });
                    Console.WriteLine("Success, user was found!\n--------------------------------------------\nUserID: " + queriedUser.UserId + "\nUsername: "******"5d":
                    Console.WriteLine("Fetching all users aggregates from Event Store...\n");
                    List <UserReadModel> userReadModels = userQueries.GetAllUsers();
                    foreach (var urm in userReadModels)
                    {
                        Console.WriteLine("UserID: " + urm.UserId + "\nUsername: "******"\n--------------------------------------------");
                    }
                    break;
                }
            } while (true);
        }
Exemple #16
0
 public GetUserQueryResult(User user)
 {
     this.User = new UserReadModel(user);
 }
        private static PostReadModel GetSamplePost2()
        {
            const string path    = "sample-post-html-2.txt";
            string       content = GetPostContent(path);

            var user = new UserReadModel
            {
                Id   = "djidiweh",
                Name = "Tugberk Ugurlu"
            };

            var samplePost = new PostReadModel
            {
                Id                   = "y9h9huj9u",
                Title                = "ASP.NET Core Authentication in a Load Balanced Environment with HAProxy and Redis",
                Abstract             = "Token based authentication is a fairly common way of authenticating a user for an HTTP application. However, handling this in a load balanced environment has always involved extra caring. In this post, I will show you how this is handled in ASP.NET Core by demonstrating it with HAProxy and Redis through the help of Docker.",
                Language             = "en-US",
                Content              = content,
                Authors              = new[] { user },
                CommentStatusActions = new[]
                {
                    new CommentStatusActionRecordReadModel
                    {
                        Status     = CommentableStatusReadModel.Enabled,
                        RecordedBy = user,
                        RecordedOn = DateTime.UtcNow
                    }
                },
                ApprovalStatus = ApprovalStatusReadModel.Approved,
                CreationRecord = new ChangeRecordReadModel
                {
                    RecordedBy = user,
                    RecordedOn = DateTime.UtcNow,
                    IpAddress  = "127.0.0.1"
                },
                Slugs = new[]
                {
                    new SlugReadModel
                    {
                        Path      = "asp-net-core-authentication-in-a-load-balanced-environment-with-haproxy-and-redis",
                        IsDefault = true,
                        CreatedOn = DateTime.UtcNow
                    }
                },
                Tags = new[]
                {
                    new TagReadModel
                    {
                        Name  = "ASP.NET Core",
                        Slugs = new[]
                        {
                            new SlugReadModel
                            {
                                Path      = "asp-net-core",
                                IsDefault = true,
                                CreatedOn = DateTime.UtcNow
                            }
                        }
                    },

                    new TagReadModel
                    {
                        Name  = "ASP.NET",
                        Slugs = new[]
                        {
                            new SlugReadModel
                            {
                                Path      = "asp-net",
                                IsDefault = true,
                                CreatedOn = DateTime.UtcNow
                            }
                        }
                    },

                    new TagReadModel
                    {
                        Name  = "Security",
                        Slugs = new[]
                        {
                            new SlugReadModel
                            {
                                Path      = "security",
                                IsDefault = true,
                                CreatedOn = DateTime.UtcNow
                            }
                        }
                    },

                    new TagReadModel
                    {
                        Name  = "HTTP",
                        Slugs = new[]
                        {
                            new SlugReadModel
                            {
                                Path      = "http",
                                IsDefault = true,
                                CreatedOn = DateTime.UtcNow
                            }
                        }
                    },

                    new TagReadModel
                    {
                        Name  = "Docker",
                        Slugs = new[]
                        {
                            new SlugReadModel
                            {
                                Path      = "docker",
                                IsDefault = true,
                                CreatedOn = DateTime.UtcNow
                            }
                        }
                    }
                }
            };

            return(samplePost);
        }
        private static PostReadModel GetSamplePost1()
        {
            const string path    = "sample-post-html-1.txt";
            string       content = GetPostContent(path);

            var user = new UserReadModel
            {
                Id   = "djidiweh",
                Name = "Tugberk Ugurlu"
            };

            var samplePost = new PostReadModel
            {
                Id                   = "ydy982d",
                Title                = "Defining What Good Looks Like for a Software Engineer",
                Abstract             = "What does good look like for a software engineer? This is a question you might be asking frequently to yourself and I tried to share my thoughts on the topic with this blog post.",
                Language             = "en-US",
                Content              = content,
                Authors              = (new[] { user }),
                CommentStatusActions = new[]
                {
                    new CommentStatusActionRecordReadModel
                    {
                        Status     = CommentableStatusReadModel.Enabled,
                        RecordedBy = user,
                        RecordedOn = DateTime.UtcNow
                    }
                },
                ApprovalStatus = ApprovalStatusReadModel.Approved,
                CreationRecord = new ChangeRecordReadModel
                {
                    RecordedBy = user,
                    RecordedOn = DateTime.UtcNow,
                    IpAddress  = "127.0.0.1"
                },
                Slugs = new[]
                {
                    new SlugReadModel
                    {
                        Path      = "defining-what-good-looks-like-for-a-software-engineer",
                        IsDefault = true,
                        CreatedOn = DateTime.UtcNow
                    }
                },
                Tags = new[]
                {
                    new TagReadModel
                    {
                        Name  = "Software Engineer",
                        Slugs = new[]
                        {
                            new SlugReadModel
                            {
                                Path      = "software-engineer",
                                IsDefault = true,
                                CreatedOn = DateTime.UtcNow
                            }
                        }
                    },

                    new TagReadModel
                    {
                        Name  = "Software Development",
                        Slugs = new[]
                        {
                            new SlugReadModel
                            {
                                Path      = "software-development",
                                IsDefault = true,
                                CreatedOn = DateTime.UtcNow
                            }
                        }
                    }
                }
            };

            return(samplePost);
        }
 public GetAllUsersHandler(UserReadModel model)
 {
     this.Model = model ?? throw new ArgumentNullException(nameof(model));
 }
 public CreateUserCommandResult(User user)
 {
     this.User = new UserReadModel(user);
 }
        public async Task <UserReadModel> Get(Guid id)
        {
            var user = await _getUser.Execute(id);

            return(UserReadModel.From(user));
        }
Exemple #22
0
 public GetConcreteUserHandler(UserReadModel model)
 {
     this.model = model ?? throw new ArgumentNullException(nameof(model));
 }