Beispiel #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);
        }
Beispiel #2
0
 public async Task <OneononeEntity> Update(OneononeEntity oneonone)
 {
     var requestErrors = new string[]
     {
         Guid.TryParse(oneonone.Id, out var _) ? null : GlobalMessages.InvalidId(oneonone.Id),
         Enum.IsDefined(typeof(FrequencyEnum), oneonone.Frequency) ? null : OneononesMessages.InvalidFrequency((int)oneonone.Frequency),
     }.Where(e => e != null);
Beispiel #3
0
        public async Task <OneononeEntity> ObtainByPair(string leaderId, string ledId)
        {
            var(leader, led) = await employeesService.ObtainPair(leaderId, ledId);

            var oneonone = await oneononesRepository.ObtainByPair(leaderId, ledId);

            if (oneonone == null)
            {
                throw new ApiException(HttpStatusCode.NotFound, OneononesMessages.NotFound(leader.Email, led.Email));
            }

            FillEmployees(oneonone, leader, led);
            return(oneonone);
        }
Beispiel #4
0
        public async Task <IList <OneononeEntity> > ObtainByEmployee(string id)
        {
            var employee = await employeesService.Obtain(id);

            var oneononeList = await oneononesRepository.ObtainByEmployee(id);

            if (oneononeList == null || !oneononeList.Any())
            {
                throw new ApiException(HttpStatusCode.NotFound, OneononesMessages.Empty(employee.Email));
            }

            await FillEmployees(oneononeList);

            return(oneononeList);
        }
Beispiel #5
0
        public async Task <OneononeEntity> Obtain(string id)
        {
            if (!Guid.TryParse(id, out var _))
            {
                throw new ApiException(HttpStatusCode.BadRequest, GlobalMessages.InvalidId(id));
            }

            var oneonone = await oneononesRepository.Obtain(id);

            if (oneonone == null)
            {
                throw new ApiException(HttpStatusCode.NotFound, OneononesMessages.NotFound(id));
            }

            await FillEmployees(oneonone);

            return(oneonone);
        }