Ejemplo n.º 1
0
        public async Task <ServiceResponse <Vat> > Create(AddVatRequest request)
        {
            try
            {
                var vatCategory = await _vatService.FindByIdInclusive(request.VatCategoryId, x => x.Include(p => p.Vats));

                if (!vatCategory.Success)
                {
                    return(new ServiceResponse <Vat>($"The Packaging type does not exist"));
                }

                if (vatCategory.Data.Vats.Count > 0 && vatCategory.Data.Vats.Any(x => x.Rate.Equals(request.Rate)))
                {
                    return(new ServiceResponse <Vat>($"The Packaging already exist exist"));
                }

                var vat = new Vat
                {
                    Rate          = request.Rate,
                    Code          = GenerateCode(8),
                    EffectiveDate = request.EffectiveDate,
                    EndDate       = request.EndDate,
                    VatCategoryId = vatCategory.Data.Id
                };
                var exist = await _baseRepository.GetByIdAndCode(vat.Id, vat.Code);

                if (exist != null)
                {
                    return(new ServiceResponse <Vat>($"A Vat With the Provided Code and or Id Already Exist"));
                }
                var exist2 = await _baseRepository.FindOneByConditions(x => x.Rate.Equals(vat.Rate));

                if (exist2 != null)
                {
                    return(new ServiceResponse <Vat>($"A Vat With the Provided Name Already Exist"));
                }

                await _baseRepository.Create(vat);

                return(new ServiceResponse <Vat>(vat));
            }
            catch (Exception ex)
            {
                return(new ServiceResponse <Vat>($"An Error Occured While Creating The Vat. {ex.Message}"));
            }
        }
Ejemplo n.º 2
0
        //VAT SECTION
        public async Task <ActionResult> Vats(Guid id)
        {
            var vatList = new List <ListVatViewModel>();

            try
            {
                var result = await _vatCategoryService.FindByIdInclusive(id, x => x.Include(p => p.Vats));

                if (!result.Success)
                {
                    Alert($"Error! {result.Message}", NotificationType.info, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                    return(View(vatList));
                }

                ViewBag.VatCategory = result.Data;

                if (result.Data.Vats.Count > 0)
                {
                    foreach (var item in result.Data.Vats)
                    {
                        vatList.Add(new ListVatViewModel
                        {
                            Rate            = item.Rate,
                            DateCreated     = item.CreatedAt,
                            DateLastUpdated = item.LastUpdated,
                            EffectiveDate   = item.EffectiveDate,
                            Id              = item.Id,
                            EndDate         = item.EndDate,
                            VatCategoryName = result.Data.Name
                        });
                    }
                }
                return(View(vatList));
            }
            catch (Exception ex)
            {
                Alert($"Error! {ex.Message}", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View(vatList));
            }
        }