示例#1
0
        /// <summary>
        /// Handles the specified <see cref="SetUserMood"/> command.
        /// </summary>
        /// <param name="command">The command.</param>
        public void Handle(SetUserMood command)
        {
            if (command.Id == null)
            {
                throw new ArgumentNullException("command", "UserId must be specified.");
            }

            var user = _userRepository.Get(command.Id);

            if (user == null)
            {
                throw new ArgumentException(string.Format("User with such id: {0} does not exist.", command.Id));
            }

            if (user.Mood != null)
            {
                throw new ArgumentException("User can set his mood only one time per day.");
            }

            var date = DateTime.Now.Date;

            user.AddMood(command.Rate, date);

            _userRepository.Save(user);
        }
示例#2
0
        public JsonResult SetMood(string UserId, int Rate)
        {
            UserMoodViewModel model = new UserMoodViewModel {
                Rate = Rate, UserId = new Guid(UserId)
            };

            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            if (model.UserId != UserContext.Current.UserId)
            {
                throw new ArgumentException("User can change rate of the mood only for himself.");
            }

            if (model.Rate <= 0 || model.Rate > 4)
            {
                throw new ArgumentException("Rate of the mood should be more than 0 and less or equal 4.");
            }

            var userMood = _userQueryService.GetUserMood(new UserId(model.UserId));

            if (userMood != null)
            {
                throw new ArgumentException("User can set his mood only one time per day.");
            }

            var command = new SetUserMood(new UserId(model.UserId), model.Rate);

            _cmdSender.Send(command);

            return(Json(new { success = true, rate = model.Rate }));
        }