private void button9_Click(object sender, EventArgs e)
 {
     TaxReport obj = new TaxReport();
     obj.Show();
 }
예제 #2
0
        private void button9_Click(object sender, EventArgs e)
        {
            TaxReport obj = new TaxReport();

            obj.Show();
        }
        /// <summary>
        /// Saves the tax report information.
        /// </summary>
        /// <param name="taxReportView">The tax report view.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">taxReportView</exception>
        /// <exception cref="Exception">Repository.Save. Db Entity Validation Exception. Data not saved. Error: " +
        ///                                         sb.ToString()</exception>
        public string SaveTaxReportInfo(ITaxReportView taxReportView)
        {
            var result = string.Empty;

            if (taxReportView == null)
            {
                throw new ArgumentNullException(nameof(taxReportView));
            }

            var taxReport = new TaxReport()

            {
                BeneficiaryTIN = taxReportView.BeneficiaryTIN,
                BVN            = taxReportView.BVN,
                IncomeAmount   = taxReportView.IncomeAmount,
                TaxAmount      = taxReportView.TaxAmount,
                IncomeTypeId   = taxReportView.IncomeTypeId,
                Year           = taxReportView.Year
            };

            try
            {
                using (
                    var dbContext = (PitalyticsEntities)this.dbContextFactory.GetDbContext())
                {
                    var taxReportInfo = dbContext.TaxReports.SingleOrDefault(x => x.BVN == taxReport.BVN && x.BeneficiaryTIN == taxReport.BeneficiaryTIN && x.IncomeAmount == taxReport.IncomeAmount &&
                                                                             x.TaxAmount == taxReport.TaxAmount && x.Year == taxReport.Year);
                    if (taxReportInfo == null)
                    {
                        dbContext.TaxReports.Add(taxReport);
                        dbContext.SaveChanges();
                    }
                }
            }


            catch (DbEntityValidationException e)
            {
                List <String> lstErrors = new List <string>();
                foreach (var eve in e.EntityValidationErrors)
                {
                    string msg = string.Format(
                        "Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                        eve.Entry.Entity.GetType().Name,
                        eve.Entry.State);

                    lstErrors.Add(msg);

                    foreach (var ve in eve.ValidationErrors)
                    {
                        msg = string.Format("- Property: \"{0}\", Error: \"{1}\"",
                                            ve.PropertyName, ve.ErrorMessage);
                        lstErrors.Add(msg);
                    }
                }

                if (lstErrors != null && lstErrors.Count() > 0)
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (var item in lstErrors)
                    {
                        sb.Append(item + "; ");
                    }

                    throw new Exception("Repository.Save. Db Entity Validation Exception. Data not saved. Error: " +
                                        sb.ToString());
                }
            }

            catch (NotSupportedException e)
            {
            }
            return(result);
        }