예제 #1
0
        /// <summary>
        /// Get COAUnit by Id
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <CoaUnitDto> GetCoaUnitById(IdInput input)
        {
            CoaUnit coaUnit = await _coaUnitRepository.GetAsync(input.Id);

            CoaUnitDto result = coaUnit.MapTo <CoaUnitDto>();

            result.CoaId = coaUnit.Id;
            return(result);
        }
예제 #2
0
        /// <summary>
        /// Validating CoaUnit
        /// </summary>
        /// <param name="coaUnit"></param>
        /// <returns></returns>
        protected virtual async Task ValidateCoaUnitAsync(CoaUnit coaUnit)
        {
            //Validating if Duplicate COA exists
            if (CoaUnitRepository != null)
            {
                if (coaUnit.IsCorporate && coaUnit.Id == 0 && coaUnit.TypeOfChartId == TypeOfChart.HOMECOA)
                {
                    int count = (await CoaUnitRepository.CountAsync(p => p.TypeOfChartId == TypeOfChart.HOMECOA &&
                                                                    p.IsCorporate == true));
                    if (count > 0)
                    {
                        var errorMessage = L("OnlyOneHomeCoaAllowed");
                        throw new UserFriendlyException(errorMessage);
                    }
                }
                else if (coaUnit.IsCorporate && coaUnit.Id == 0 && coaUnit.TypeOfChartId == TypeOfChart.NEWCOA)
                {
                    int count = (await CoaUnitRepository.CountAsync(p => p.TypeOfChartId == TypeOfChart.NEWCOA &&
                                                                    p.IsCorporate == true));
                    if (count > 0)
                    {
                        var errorMessage = L("OnlyOneNewCoaAllowed");
                        throw new UserFriendlyException(errorMessage);
                    }
                }

                else
                {
                    var coaunit = (await CoaUnitRepository.
                                   GetAllListAsync(
                                       p => p.Caption == coaUnit.Caption && p.OrganizationUnitId == coaUnit.OrganizationUnitId));

                    if (coaUnit.Id == 0)
                    {
                        if (coaunit.Count > 0)
                        {
                            throw new UserFriendlyException(L("Duplicate ChartofAccount", coaUnit.Caption));
                        }
                    }
                    else
                    {
                        if (coaunit.FirstOrDefault(p => p.Id != coaUnit.Id && p.Caption == coaUnit.Caption) != null)
                        {
                            throw new UserFriendlyException(L("Duplicate ChartofAccount", coaUnit.Caption));
                        }
                    }
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Updating CoaUnit Details
        /// </summary>
        /// <param name="coaUnit"></param>
        /// <returns></returns>
        public virtual async Task UpdateAsync(CoaUnit coaUnit)
        {
            await ValidateCoaUnitAsync(coaUnit);

            await CoaUnitRepository.UpdateAsync(coaUnit);
        }