예제 #1
0
        public User Search(Func <User, bool> criteria)
        {
            //Console.WriteLine(criteria.Method.ToString());
            //Console.WriteLine(criteria.Target);
            if (criteria == null)
            {
                throw new ArgumentNullException(nameof(criteria));
            }
            User found = userStorage.Search(criteria);

            Message answer = null;

            if (found == null)
            {
                answer = SendMessageToMaster(new Message()
                {
                    Type     = Command.Search,
                    Criteria = criteria
                });
            }

            if (answer?.User != null)
            {
                found = answer.User;
                userStorage.Add(found);
            }

            return(found);
        }
예제 #2
0
        /// <summary>
        /// Save user aggregate root state.
        /// </summary>
        /// <param name="aggregate">The user aggregate.</param>
        public override void Save(User aggregate)
        {
            var user = new DB.Models.User.User
            {
                Id          = aggregate.Id.Id,
                FirstName   = aggregate.FirstName,
                LastName    = aggregate.LastName,
                Image       = aggregate.Image,
                Password    = aggregate.Password,
                Phone       = aggregate.Phone,
                Email       = aggregate.Email,
                DateOfBirth = aggregate.DateOfBirth,
                Roles       = aggregate.Roles,
                IsDeleted   = aggregate.IsDeleted,
                Mood        = aggregate.Mood == null ? null : new DB.Models.User.UserMood
                {
                    Date   = aggregate.Mood.Date,
                    Rate   = aggregate.Mood.Rate,
                    UserId = aggregate.Id.Id
                }
            };

            if (aggregate.IsNew)
            {
                _userStorage.Add(user);
            }
            else
            {
                _userStorage.Update(user);
            }
        }
예제 #3
0
        public void Add(User user, AbstractValidator <User> validator)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            ValidationResult results = validator.Validate(user);

            if (!results.IsValid)
            {
                throw new ValidationException(results.Errors);
            }

            user.Id = idGenerator.GenerateNext();
            userStorage.Add(user);

            SendNotificationToAllSlaves(new Message()
            {
                Type = Command.Add,
                User = user
            });
        }
예제 #4
0
        public async Task <OperationResult> Add(RegisterVM registerVM, HttpContext httpContext, IUrlHelper Url)
        {
            var result = await _userStorage.Add(registerVM, httpContext, Url);

            return(result);
        }
 public bool Registration([FromBody] RegistrationVM registrationVM)
 {
     return(_userStorage.Add(registrationVM));
 }