Пример #1
0
        private bool TargetIdExists(RateMusician rateMusician)
        {
            MusicianRepository musicianRepository = new MusicianRepository();
            var retorno = musicianRepository.Get(rateMusician.musician_target_id);

            return(retorno != null);
        }
Пример #2
0
        internal RateMusician GetByOwnerId(int musician_target_id)
        {
            int musician_owner_id = Utitilities.GetLoggedUserId();

            RateMusician retorno = _rateMusicianBusiness.GetByOwnerId(musician_target_id, musician_owner_id);

            return(retorno);
        }
Пример #3
0
        public IHttpActionResult Get([FromUri] int id)
        {
            RateMusician      rateMusician      = null;
            RateMusicianModel rateMusicianModel = new RateMusicianModel();

            try
            {
                rateMusician = rateMusicianModel.GetByOwnerId(id);
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            return(Ok(rateMusician));
        }
Пример #4
0
        public IHttpActionResult Create([FromBody] RateMusicianModel rate_musician)
        {
            RateMusician rateMusician = null;

            try
            {
                rateMusician = rate_musician.Create();
            }
            catch (ValidateException ex)
            {
                return(UnprocessableEntity(ex.Message));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            return(Created("api", rateMusician));
        }
Пример #5
0
        public RateMusician Create(RateMusician rateMusician)
        {
            PopulateDefaultProperties(rateMusician);

            Validate(rateMusician);

            RateMusician objExistente = GetByOwnerId(rateMusician.musician_target_id, rateMusician.musician_owner_id);
            RateMusician retorno      = null;

            if (objExistente != null && objExistente.id > 0)
            {
                rateMusician.id = objExistente.id;
                retorno         = _rateMusicianRepository.Update(rateMusician);
            }
            else
            {
                retorno = _rateMusicianRepository.Create(rateMusician);
            }

            return(retorno);
        }
Пример #6
0
        private void Validate(RateMusician rateMusician)
        {
            if (rateMusician.musician_target_id == 0)
            {
                throw ValidateException("O músico deve ser selecionado!");
            }

            if (rateMusician.musician_target_id == rateMusician.musician_owner_id)
            {
                throw ValidateException("Você não pode votar em si mesmo!");
            }

            bool targetIdExists = TargetIdExists(rateMusician);

            if (!targetIdExists)
            {
                throw ValidateException("O ID deste usuario é inexistente!");
            }

            if (rateMusician.rate_value <= 0 || rateMusician.rate_value > 5)
            {
                throw ValidateException("O voto deve ser de 1 a 5!");
            }
        }
Пример #7
0
 private void PopulateDefaultProperties(RateMusician rateMusician)
 {
     rateMusician.musician_owner_id = Utitilities.GetLoggedUserId();
 }
Пример #8
0
        public RateMusician GetByOwnerId(int musician_target_id, int musician_owner_id)
        {
            RateMusician retorno = _rateMusicianRepository.GetByOwnerId(musician_target_id, musician_owner_id);

            return(retorno);
        }
Пример #9
0
        internal RateMusician Create()
        {
            RateMusician retorno = _rateMusicianBusiness.Create(this);

            return(retorno);
        }