Ejemplo n.º 1
0
        public async Task <OneononeEntity> Insert(OneononeInputEntity oneononeInput)
        {
            if (!Enum.IsDefined(typeof(FrequencyEnum), oneononeInput.Frequency))
            {
                throw new ApiException(HttpStatusCode.BadRequest, OneononesMessages.InvalidFrequency((int)oneononeInput.Frequency));
            }

            var(leader, led) = await employeesService.ObtainPair(oneononeInput?.LeaderId, oneononeInput?.LedId);

            var oneononeObtained = await oneononesRepository.ObtainByPair(leader.Id, led.Id);

            if (oneononeObtained != null)
            {
                throw new ApiException(HttpStatusCode.Conflict, OneononesMessages.Conflict(leader.Email, led.Email));
            }

            var oneonone = new OneononeEntity(leader, led, oneononeInput.Frequency);
            var inserted = await oneononesRepository.Insert(oneonone);

            if (!inserted)
            {
                throw new ApiException(HttpStatusCode.InternalServerError, OneononesMessages.Insert(oneonone.Leader.Email, oneonone.Led.Email));
            }

            return(oneonone);
        }
Ejemplo n.º 2
0
        public static OneononeInputEntity ToEntity(this OneononeInputViewModel viewModel)
        {
            if (viewModel == null)
            {
                return(null);
            }

            var entity = new OneononeInputEntity
            {
                LeaderId  = viewModel.LeaderId,
                LedId     = viewModel.LedId,
                Frequency = viewModel.Frequency,
            };

            return(entity);
        }