예제 #1
0
        public async void Tax_add_to_municpality_and_get_from_location()
        {
            using (var ctx = new TaxesDbContext()) {
                ctx.Municipalities.Add(new Municipality("Vilnius"));
                await ctx.SaveChangesAsync();

                var tax = new TaxPost {
                    DateFrom = new DateTime(2017, 1, 1),
                    DateTo   = new DateTime(2017, 1, 10),
                    Rate     = (decimal)0.5
                };
                //var content = new
                var result = await _server.HttpClient.PostAsync("api/taxes/Vilnius", new ObjectContent(typeof(TaxPost), tax, new JsonMediaTypeFormatter()));

                var responseContent = await result.Content.ReadAsAsync <Guid>();

                Assert.True(result.IsSuccessStatusCode);

                var location  = result.Headers.Location;
                var getResult = await _server.HttpClient.GetAsync(location);

                Assert.True(getResult.IsSuccessStatusCode);

                var savedTax = await getResult.Content.ReadAsAsync <TaxGet>();

                Assert.Equal(savedTax.Id, responseContent);
                Assert.Equal(savedTax.DateFrom, tax.DateFrom);
                Assert.Equal(savedTax.DateTo, tax.DateTo.Value);
                Assert.Equal(savedTax.Rate, tax.Rate);
            }
        }
예제 #2
0
        public List <string> SaveTax(TaxPost tax)
        {
            try
            {
                //validate Business Rule
                DataTable     dtTaxTrans   = CollectionHelper.ConvertTo(tax.TransData, "");
                List <string> ErrorMessage = new List <string>();
                BaseBusiness  baseBusiness = new BaseBusiness();
                //if (!baseBusiness.ValidateBaseBusiness("Tax", dtCreateTax, "SAVE"))
                //{
                //    ErrorMessage = baseBusiness.ErrorMessage;
                //    return ErrorMessage;
                //}

                if (tax.CitySNo == "")
                {
                    tax.CitySNo = "0";
                }
                SqlParameter[] Parameters = { new SqlParameter("@TaxCode",     tax.TaxCode),
                                              new SqlParameter("@TaxType",     tax.TaxType),
                                              new SqlParameter("@Description", tax.Description),
                                              new SqlParameter("@CountrySNo",  tax.CountrySNo),
                                              new SqlParameter("@CitySNo",     tax.CitySNo),
                                              new SqlParameter("@IsActive",    tax.IsActive),
                                              new SqlParameter("@UpdatedBy",   tax.UpdatedBy),
                                              new SqlParameter("@TaxTrans",    SqlDbType.Structured)
                                              {
                                                  Value = dtTaxTrans
                                              } };

                int ret = (int)SqlHelper.ExecuteScalar(DMLConnectionString.WebConfigConnectionString, "spTax_Create", Parameters);
                if (ret > 0)
                {
                    if (ret > 1000)
                    {
                        //For Customised Validation Messages like 'Record Already Exists' etc
                        string serverErrorMessage = baseBusiness.ReadServerErrorMessages(ret, "Tax");
                        if (!string.IsNullOrEmpty(serverErrorMessage))
                        {
                            ErrorMessage.Add(serverErrorMessage);
                        }
                    }
                    else
                    {
                        //For DataBase Exceptions like 'Foreign Key refrence Errors' etc
                        string dataBaseExceptionMessage = baseBusiness.ReadServerErrorMessages(ret, baseBusiness.DatabaseExceptionFileName);
                        if (!string.IsNullOrEmpty(dataBaseExceptionMessage))
                        {
                            ErrorMessage.Add(dataBaseExceptionMessage);
                        }
                    }
                }

                return(ErrorMessage);
            }
            catch (Exception ex)//(Exception ex)
            {
                throw ex;
            }
        }