Exemplo n.º 1
0
        //--------------- Business Logic ---------------

        private async Task <ActualResult> CheckDate(PrivateHouseEmployeesDTO dto)
        {
            try
            {
                var id       = HashHelper.DecryptLong(dto.HashIdEmployee);
                var employee = await _context.Employee.FindAsync(id);

                if (employee != null)
                {
                    var listErrors = new List <string>();
                    if (employee.StartDateTradeUnion > dto.DateReceiving)
                    {
                        listErrors.Add("Дата вступу в профспілку більша за дату розподілу!");
                    }
                    if (employee.EndDateTradeUnion != null)
                    {
                        if (employee.EndDateTradeUnion < dto.DateReceiving)
                        {
                            listErrors.Add("Дата виходу з профспілки не може бути меншою, ніж дата розподілу!");
                        }
                    }
                    return(listErrors.Any() ? new ActualResult(listErrors) : new ActualResult());
                }
                return(new ActualResult(Errors.TupleDeleted));
            }
            catch (Exception exception)
            {
                return(new ActualResult(DescriptionExceptionHelper.GetDescriptionError(exception)));
            }
        }
Exemplo n.º 2
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)));
            }
        }
Exemplo n.º 3
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)));
            }
        }