コード例 #1
0
        public async Task <ActualResult> UpdateAsync(PrivateHouseEmployeesDTO item, PrivateHouse type)
        {
            try
            {
                switch (type)
                {
                case PrivateHouse.PrivateHouse:
                    _context.Entry(_mapper.Map <PrivateHouseEmployees>(item)).State = EntityState.Modified;
                    await _context.SaveChangesAsync();

                    return(new ActualResult());

                case PrivateHouse.UniversityHouse:
                    var check = await CheckDate(item);

                    if (check.IsValid)
                    {
                        _context.Entry(_mapper.Map <PrivateHouseEmployees>(item)).State = EntityState.Modified;
                        await _context.SaveChangesAsync();

                        return(new ActualResult());
                    }
                    return(check);

                default:
                    throw new ArgumentOutOfRangeException(nameof(type), type, null);
                }
            }
            catch (Exception exception)
            {
                return(new ActualResult(DescriptionExceptionHelper.GetDescriptionError(exception)));
            }
        }
コード例 #2
0
        public async Task <ActualResult> CreateAsync(PrivateHouseEmployeesDTO item, PrivateHouse type)
        {
            try
            {
                switch (type)
                {
                case PrivateHouse.PrivateHouse:
                {
                    var privateHouse = _mapper.Map <PrivateHouseEmployees>(item);
                    await _context.PrivateHouseEmployees.AddAsync(privateHouse);

                    await _context.SaveChangesAsync();

                    var hashId = HashHelper.EncryptLong(privateHouse.Id);
                    return(new ActualResult <string> {
                            Result = hashId
                        });
                }

                case PrivateHouse.UniversityHouse:
                {
                    var check = await CheckDate(item);

                    if (check.IsValid)
                    {
                        var universityHouse = _mapper.Map <PrivateHouseEmployees>(item);
                        await _context.PrivateHouseEmployees.AddAsync(universityHouse);

                        await _context.SaveChangesAsync();

                        var hashId = HashHelper.EncryptLong(universityHouse.Id);
                        return(new ActualResult <string> {
                                Result = hashId
                            });
                    }
                    return(check);
                }

                default:
                    throw new ArgumentOutOfRangeException(nameof(type), type, null);
                }
            }
            catch (Exception exception)
            {
                return(new ActualResult(DescriptionExceptionHelper.GetDescriptionError(exception)));
            }
        }
コード例 #3
0
        public async Task <ActualResult <IEnumerable <PrivateHouseEmployeesDTO> > > GetAllAsync(string hashIdEmployee, PrivateHouse type)
        {
            try
            {
                IEnumerable <PrivateHouseEmployees> result;
                var idEmployee = HashHelper.DecryptLong(hashIdEmployee);
                switch (type)
                {
                case PrivateHouse.PrivateHouse:
                    result = await _context.PrivateHouseEmployees.Where(x => x.IdEmployee == idEmployee && x.DateReceiving == null).ToListAsync();

                    break;

                case PrivateHouse.UniversityHouse:
                    result = await _context.PrivateHouseEmployees.Where(x => x.IdEmployee == idEmployee && x.DateReceiving != null).ToListAsync();

                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(type), type, null);
                }
                var mapping = _mapper.Map <IEnumerable <PrivateHouseEmployeesDTO> >(result);
                return(new ActualResult <IEnumerable <PrivateHouseEmployeesDTO> > {
                    Result = mapping
                });
            }
            catch (Exception exception)
            {
                return(new ActualResult <IEnumerable <PrivateHouseEmployeesDTO> >(DescriptionExceptionHelper.GetDescriptionError(exception)));
            }
        }