/// <summary> /// Построить конверт SOAP-запроса /// </summary> /// <param name="model"> /// Модель конверта SOAP-запроса /// </param> /// <returns> /// Конверт SOAP-запроса /// </returns> public static string Build(EnvelopeModel model) { return string.Format( @"<SOAP-ENV:Envelope xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""> <SOAP-ENV:Header> </SOAP-ENV:Header> <SOAP-ENV:Body wsu:Id=""{0}"" xmlns:wsu=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"" xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/""> <{1} xmlns=""http://wslouch.micex.com/""> </{1}> </SOAP-ENV:Body> </SOAP-ENV:Envelope>", model.RequestId, model.MethodName); }
/// <summary> /// Построить конверт SOAP-запроса /// </summary> /// <param name="model"> /// Модель конверта SOAP-запроса /// </param> /// <returns> /// Конверт SOAP-запроса /// </returns> public static string Build(EnvelopeModel model) { return(string.Format( @"<SOAP-ENV:Envelope xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""> <SOAP-ENV:Header> </SOAP-ENV:Header> <SOAP-ENV:Body wsu:Id=""{0}"" xmlns:wsu=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"" xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/""> <{1} xmlns=""http://wslouch.micex.com/""> </{1}> </SOAP-ENV:Body> </SOAP-ENV:Envelope>", model.RequestId, model.MethodName)); }
public async Task <IActionResult> Put([FromBody] EnvelopeModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } int organizationId = 0; var organizationIdVal = User.FindFirst(ClaimTypes.Country)?.Value; bool isValid = int.TryParse(organizationIdVal, out organizationId); if (organizationId == 0) { return(BadRequest("A bad attempt to access the envelope")); } decimal exchangeRate = 1; var dated = DateTime.Now; var rates = await exchangeRateService.GetCurrencyRatesForDate(dated); if (rates.Rates == null) { string apiKey = exchangeRateService.GetAPIKeyForOpenExchange(); rates = await exchangeRateHttpService.GetRatesAsync(apiKey); if (rates.Rates != null) { await exchangeRateService.SaveCurrencyRatesAsync(rates.Rates, DateTime.Now); exchangeRate = currencyService.GetExchangeRateForCurrency(model.Currency, rates.Rates); } } else { exchangeRate = currencyService.GetExchangeRateForCurrency(model.Currency, rates.Rates); } model.ExchangeRate = exchangeRate; var response = await envelopeService.AddAsync(model, organizationId); if (!response.Success) { return(BadRequest(response.Message)); } return(Ok(true)); }
public async Task <ActionResponse> AddAsync(EnvelopeModel model, int funderId) { using (var unitWork = new UnitOfWork(context)) { ActionResponse response = new ActionResponse(); try { var envelope = unitWork.EnvelopeRepository.GetOne(e => e.FunderId == funderId); int fyMonth = 1, fyDay = 1; var fySettings = unitWork.FinancialYearSettingsRepository.GetOne(fy => fy.Id != 0); if (fySettings != null) { fyMonth = fySettings.Month; fyDay = fySettings.Day; } int currentYear = DateTime.Now.Year, currentMonth = DateTime.Now.Month, currentDay = DateTime.Now.Day; bool isSimilarToCalendarYear = (fyMonth == 1 && fyDay == 1) ? true : false; if (!isSimilarToCalendarYear) { if (currentMonth < fyMonth) { --currentYear; } else if (currentMonth == fyMonth && currentDay < fyDay) { --currentYear; } } var financialYears = unitWork.FinancialYearRepository.GetManyQueryable(y => y.FinancialYear >= (currentYear - 1) && y.FinancialYear <= (currentYear + 1)); var envelopeTypes = unitWork.EnvelopeTypesRepository.GetManyQueryable(e => e.Id != 0); var strategy = context.Database.CreateExecutionStrategy(); await strategy.ExecuteAsync(async() => { using (var transaction = context.Database.BeginTransaction()) { if (envelope == null) { envelope = unitWork.EnvelopeRepository.Insert(new EFEnvelope() { FunderId = funderId, Currency = model.Currency, ExchangeRate = model.ExchangeRate, }); } else { envelope.Currency = model.Currency; envelope.ExchangeRate = model.ExchangeRate; unitWork.EnvelopeRepository.Update(envelope); } await unitWork.SaveAsync(); var yearlyBreakups = unitWork.EnvelopeYearlyBreakupRepository.GetWithInclude(e => e.EnvelopeId == envelope.Id, new string[] { "Year" }); List <EFEnvelopeYearlyBreakup> newYearlyBreakups = new List <EFEnvelopeYearlyBreakup>(); foreach (var breakup in model.EnvelopeBreakups) { var isBreakupExists = (from b in yearlyBreakups where b.Year.FinancialYear == breakup.Year && envelope.Id == b.EnvelopeId && b.EnvelopeTypeId == breakup.EnvelopeTypeId select b).FirstOrDefault(); if (isBreakupExists == null) { var financialYear = (from fy in financialYears where fy.FinancialYear == breakup.Year select fy).FirstOrDefault(); if (financialYear == null) { financialYear = unitWork.FinancialYearRepository.Insert(new EFFinancialYears() { FinancialYear = breakup.Year }); unitWork.Save(); } var envelopeType = (from t in envelopeTypes where t.Id == breakup.EnvelopeTypeId select t).FirstOrDefault(); if (envelopeType != null) { newYearlyBreakups.Add(new EFEnvelopeYearlyBreakup() { EnvelopeType = envelopeType, Year = financialYear, Amount = breakup.Amount, Envelope = envelope }); } } else { isBreakupExists.Amount = breakup.Amount; unitWork.EnvelopeYearlyBreakupRepository.Update(isBreakupExists); unitWork.Save(); } } if (newYearlyBreakups.Count > 0) { unitWork.EnvelopeYearlyBreakupRepository.InsertMultiple(newYearlyBreakups); await unitWork.SaveAsync(); } transaction.Commit(); } }); } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return(response); } }