Example #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);
        }
        public async Task <bool> Update(OneononeEntity oneononeEntity)
        {
            var oneononeModel = oneononeEntity.ToModel();
            var rowsAffected  = await oneononesDatabase.Update(oneononeModel);

            return(rowsAffected == 1);
        }
Example #3
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);
Example #4
0
        private async Task <OneononeComposeEntity> ObtainEmployeeOneononeCompose(OneononeEntity oneonone)
        {
            var historical = await ObtainHistoricalByPair(oneonone.Leader.Id, oneonone.Led.Id);

            StatusEntity status = ObtainStatusByHistorical(historical, oneonone.Frequency);

            var oneononeComposeEntity = new OneononeComposeEntity
            {
                Oneonone   = oneonone,
                Historical = historical,
                Status     = status,
            };

            return(oneononeComposeEntity);
        }
Example #5
0
        public static OneononeEntity ToEntity(this OneononeViewModel viewModel)
        {
            if (viewModel?.Leader == null || viewModel?.Led == null)
            {
                return(null);
            }

            var entity = new OneononeEntity
            {
                Id        = viewModel.Id,
                Leader    = viewModel.Leader.ToEntity(),
                Led       = viewModel.Led.ToEntity(),
                Frequency = viewModel.Frequency,
            };

            return(entity);
        }
Example #6
0
        public static OneononeViewModel ToViewModel(this OneononeEntity entity)
        {
            if (entity == null)
            {
                return(null);
            }

            var viewModel = new OneononeViewModel
            {
                Id        = entity.Id,
                Leader    = entity.Leader.ToViewModel(),
                Led       = entity.Led.ToViewModel(),
                Frequency = entity.Frequency,
            };

            return(viewModel);
        }
Example #7
0
        public static OneononeModel ToModel(this OneononeEntity entity)
        {
            if (entity == null)
            {
                return(null);
            }

            var model = new OneononeModel
            {
                Id        = entity.Id,
                LeaderId  = entity.Leader.Id,
                LedId     = entity.Led.Id,
                Frequency = (int)entity.Frequency,
            };

            return(model);
        }
Example #8
0
        public static OneononeEntity ToEntity(this OneononeModel model)
        {
            if (model == null)
            {
                return(null);
            }

            var entity = new OneononeEntity
            {
                Id     = model.Id,
                Leader = new EmployeeEntity {
                    Id = model.LeaderId
                },
                Led = new EmployeeEntity {
                    Id = model.LedId
                },
                Frequency = (FrequencyEnum)model.Frequency,
            };

            return(entity);
        }