예제 #1
0
        public IActionResult Update([FromBody] ConsumerTo consumerModel)
        {
            if (consumerModel.ConsumerId == null)
            {
                return(BadRequest(ValidationMessages.ConsumerIdRequired));
            }
            if (consumerModel.RegionId == null)
            {
                return(BadRequest(ValidationMessages.RegionIdRequired));
            }
            if (!IsValidSystemId(consumerModel.SystemId))
            {
                return(BadRequest(ValidationMessages.SystemIdRequired));
            }
            if (!IsValidEmail(consumerModel.Email))
            {
                return(BadRequest(ValidationMessages.InvalidEmailFormat));
            }

            var oldConsumer = _repository.Query <Consumer>().AsNoTracking().FirstOrDefault(x => x.Id == consumerModel.ConsumerId);

            if (oldConsumer == null)
            {
                return(BadRequest(ValidationMessages.ConsumerNotFound));
            }
            if (oldConsumer.PrimaryEmail.ToLower() != consumerModel.Email.ToLower())
            {
                var user           = _userClaimResolver.Resolve();
                var canChangeEmail = user.Claims.FirstOrDefault(x => x.Type == "CanChangeEmail");
                if (canChangeEmail == null || !Convert.ToBoolean(canChangeEmail.Value))
                {
                    return(BadRequest(ValidationMessages.ConsumerFoundButEmailIsNotMatch));
                }
            }

            return(AddUpdate(consumerModel, true));
        }
예제 #2
0
        public string Resolve()
        {
            var userid = _userManager.GetUserId(_userClaimResolver.Resolve());

            return(userid);
        }