public async Task <IActionResult> ExemptionCertificates() { var customer = await _workContext.GetCurrentCustomerAsync(); if (!await _customerService.IsRegisteredAsync(customer)) { return(Challenge()); } //ensure that Avalara tax provider is active if (!await _taxPluginManager.IsPluginActiveAsync(AvalaraTaxDefaults.SystemName, customer)) { return(RedirectToRoute("CustomerInfo")); } if (!_avalaraTaxSettings.EnableCertificates) { return(RedirectToRoute("CustomerInfo")); } //ACL if (_avalaraTaxSettings.CustomerRoleIds.Any()) { var customerRoleIds = await _customerService.GetCustomerRoleIdsAsync(customer); if (!customerRoleIds.Intersect(_avalaraTaxSettings.CustomerRoleIds).Any()) { return(RedirectToRoute("CustomerInfo")); } } var token = await _avalaraTaxManager.CreateTokenAsync(customer); var link = await _avalaraTaxManager.GetInvitationAsync(customer) ?? AvalaraTaxDefaults.CertExpressUrl; var certificates = await _avalaraTaxManager.GetCustomerCertificatesAsync(customer); var model = new TaxExemptionModel { Token = token, Link = link, CustomerId = customer.Id, Certificates = certificates?.Select(certificate => new ExemptionCertificateModel { Id = certificate.id ?? 0, Status = certificate.status, SignedDate = certificate.signedDate.ToShortDateString(), ExpirationDate = certificate.expirationDate.ToShortDateString(), ExposureZone = certificate.exposureZone?.name }).ToList() ?? new List <ExemptionCertificateModel>() }; model.AvailableExposureZones = (await _avalaraTaxManager.GetExposureZonesAsync()) .Select(zone => new SelectListItem(zone.name, zone.name)) .ToList(); return(View("~/Plugins/Tax.Avalara/Views/Customer/ExemptionCertificates.cshtml", model)); }
public HttpResponseMessage SetTaxExemption([FromBody] TaxExemptionModel model) { var dateStart = DateTime.Now; _performancelog.Debug($"Start,SaleController,SetTaxExemption,{string.Empty},{DateTime.Now:hh.mm.ss.ffffff}"); string userCode; HttpResponseMessage httpResponseMessage; if (GetUserCode(out userCode, out httpResponseMessage)) { return(httpResponseMessage); } ErrorMessage error; var sale = _saleManager.SetTaxExemptionCode(model.SaleNumber, model.TillNumber, userCode, model.TaxExemptionCode, out error); if (!string.IsNullOrEmpty(error.MessageStyle.Message)) { return(Request.CreateResponse( HttpStatusCode.NotFound, new ErrorResponse { Error = error.MessageStyle })); } if (sale != null) { var editLines = _saleManager.CheckEditOptions(sale.Sale_Lines, userCode); var enableButtons = _saleManager.EnableCashButton(sale, userCode); var userCanWriteOff = _saleManager.EnableWriteOffButton(userCode); var saleModel = SaleMapper.CreateSaleModel(sale, editLines, enableButtons, userCanWriteOff); _performancelog.Debug( $"End,SaleController,SetTaxExemption,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}"); return(Request.CreateResponse(HttpStatusCode.OK, saleModel)); } return(Request.CreateResponse(HttpStatusCode.BadRequest, new ErrorResponse { Error = new MessageStyle { Message = Resource.SaleNotExist, MessageType = (MessageType)16 } })); }