private void Save(Takers takers, Companys companys, CFPS cFPS, ShippingCompany shippingCompany, Models.Models.NFeSStructure.NFeSProcessingResult.tbnfd NFeS, Models.Models.NFeSStructure.NFeSPreview.util NFeSUrl, string XML = "", string PDF = "") { try { var NFDet = NFeS.nfdok.NewDataSet.NOTA_FISCAL; SQL = new StringBuilder(); SQL.AppendLine("Insert Into NFeS "); SQL.AppendLine(" ( TakerId , "); SQL.AppendLine(" CompanyId , "); SQL.AppendLine(" CFPSId , "); SQL.AppendLine(" ShippingCompanyId , "); SQL.AppendLine(" Cae , "); SQL.AppendLine(" DataEmissao , "); SQL.AppendLine(" NaturezaOperacao , "); SQL.AppendLine(" NumeroNota , "); SQL.AppendLine(" NumeroRps , "); SQL.AppendLine(" SituacaoNf , "); SQL.AppendLine(" ChaveValidacao , "); SQL.AppendLine(" ClienteNomeRazaoSocial , "); SQL.AppendLine(" ClienteNomeFantasia , "); SQL.AppendLine(" ClienteCNPJCPF , "); SQL.AppendLine(" ClienteEndereco , "); SQL.AppendLine(" ClienteBairro , "); SQL.AppendLine(" ClienteNumeroLogradouro , "); SQL.AppendLine(" ClienteCidade , "); SQL.AppendLine(" ClienteUF , "); SQL.AppendLine(" ClientePais , "); SQL.AppendLine(" ClienteFone , "); SQL.AppendLine(" ClienteFax , "); SQL.AppendLine(" ClienteInscricaoMunicipal , "); SQL.AppendLine(" ClienteCEP , "); SQL.AppendLine(" ClienteEmail , "); SQL.AppendLine(" ClienteInscricaoEstadual , "); SQL.AppendLine(" BaseCalculo , "); SQL.AppendLine(" ISSQNCliente , "); SQL.AppendLine(" ISSQNSemRetencao , "); SQL.AppendLine(" ISSQNTotal , "); SQL.AppendLine(" Irrf , "); SQL.AppendLine(" Cofins , "); SQL.AppendLine(" Inss , "); SQL.AppendLine(" Csll , "); SQL.AppendLine(" Pis , "); SQL.AppendLine(" ValorTotalNota , "); SQL.AppendLine(" FreteCNPJ , "); SQL.AppendLine(" FreteRazaoSocial , "); SQL.AppendLine(" FreteEndereco , "); SQL.AppendLine(" FreteEmitente , "); SQL.AppendLine(" FreteDestinatario , "); SQL.AppendLine(" FreteQuantidade , "); SQL.AppendLine(" FreteEspecie , "); SQL.AppendLine(" FretePesoLiquido , "); SQL.AppendLine(" FretePesoBruto , "); SQL.AppendLine(" Serie , "); SQL.AppendLine(" SerieSimplificada , "); SQL.AppendLine(" CodigoSerie , "); SQL.AppendLine(" Observacao , "); SQL.AppendLine(" ServicoCidade , "); SQL.AppendLine(" ServicoEstado , "); SQL.AppendLine(" TimbreContribuinteLogo , "); SQL.AppendLine(" TimbreContribuinteLinha1 , "); SQL.AppendLine(" TimbreContribuinteLinha2 , "); SQL.AppendLine(" TimbreContribuinteLinha3 , "); SQL.AppendLine(" TimbreContribuinteLinha4 , "); SQL.AppendLine(" TimbrePrefeituraLogo , "); SQL.AppendLine(" TimbrePrefeituraLinha1 , "); SQL.AppendLine(" TimbrePrefeituraLinha2 , "); SQL.AppendLine(" TimbrePrefeituraLinha3 , "); SQL.AppendLine(" URLAutenticidade , "); SQL.AppendLine(" URL , "); SQL.AppendLine(" NotaFiscalPDF , "); SQL.AppendLine(" NotaFiscalXML , "); SQL.AppendLine(" Active , "); SQL.AppendLine(" DateInsert , "); SQL.AppendLine(" DateUpdate "); SQL.AppendLine(" ) "); SQL.AppendLine("Values ( " + takers.TakerId.ToString() + " , "); SQL.AppendLine(" " + companys.CompanyId.ToString() + " , "); SQL.AppendLine(" " + cFPS.CFPSId.ToString() + " , "); SQL.AppendLine(" " + (shippingCompany.ShippingCompanyId == 0 ? "Null" : shippingCompany.ShippingCompanyId.ToString()) + " , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.Cae) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.DataEmissao) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.NaturezaOperacao) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.NumeroNota) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.NumeroRps) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.SituacaoNf) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.ChaveValidacao) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.ClienteNomeRazaoSocial) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.ClienteNomeFantasia) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.ClienteCNPJCPF) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.ClienteEndereco) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.ClienteBairro) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.ClienteNumeroLogradouro) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.ClienteCidade) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.ClienteUF) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.ClientePais) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.ClienteFone) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.ClienteFax) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.ClienteInscricaoMunicipal) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.ClienteCEP) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.ClienteEmail) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.ClienteInscricaoEstadual) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.BaseCalculo) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.ISSQNCliente) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.ISSQNSemRetencao) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.ISSQNTotal) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.Irrf) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.Cofins) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.Inss) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.Csll) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.Pis) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.ValorTotalNota) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.FreteCNPJ) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.FreteRazaoSocial) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.FreteEndereco) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.FreteEmitente) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.FreteDestinatario) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.FreteQuantidade) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.FreteEspecie) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.FretePesoLiquido) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.FretePesoBruto) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.Serie) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.SerieSimplificada) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.CodigoSerie) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.Observacao) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.servicoCidade) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFDet.servicoEstado) + "' , "); SQL.AppendLine(" '' , "); SQL.AppendLine(" '' , "); SQL.AppendLine(" '' , "); SQL.AppendLine(" '' , "); SQL.AppendLine(" '' , "); SQL.AppendLine(" '' , "); SQL.AppendLine(" '' , "); SQL.AppendLine(" '' , "); SQL.AppendLine(" '' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFeSUrl.urlAutenticidade) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(NFeSUrl.urlNfd) + "' , "); SQL.AppendLine(" '" + (string.IsNullOrEmpty(PDF) ? string.Empty : Functions.NoQuote(PDF)) + "' , "); SQL.AppendLine(" '" + (string.IsNullOrEmpty(XML)? string.Empty:Functions.NoQuote(XML)) + "' , "); SQL.AppendLine(" 1 , "); SQL.AppendLine(" '" + Functions.DateTimeBr().ToString("yyyy-MM-dd HH:mm:ss") + "' , "); SQL.AppendLine(" '" + Functions.DateTimeBr().ToString("yyyy-MM-dd HH:mm:ss") + "' "); SQL.AppendLine(" )"); long Id = Functions.Conn.Insert(SQL.ToString()); if (Id > 0) { SQL = new StringBuilder(); foreach (var Fat in NFDet.FATURA) { SQL.AppendLine("Insert Into NFeSInvoices "); SQL.AppendLine(" ( NFeSId , "); SQL.AppendLine(" Numero , "); SQL.AppendLine(" Vencimento , "); SQL.AppendLine(" Valor , "); SQL.AppendLine(" Active , "); SQL.AppendLine(" DateInsert , "); SQL.AppendLine(" DateUpdate "); SQL.AppendLine(" ) "); SQL.AppendLine("Values ( " + Id + " , "); SQL.AppendLine(" '" + Functions.NoQuote(Fat.Numero) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(Fat.Vencimento) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(Fat.Valor) + "' , "); SQL.AppendLine(" 1 , "); SQL.AppendLine(" '" + Functions.DateTimeBr().ToString("yyyy-MM-dd HH:mm:ss") + "' , "); SQL.AppendLine(" '" + Functions.DateTimeBr().ToString("yyyy-MM-dd HH:mm:ss") + "' "); SQL.AppendLine(" )"); SQL.AppendLine(" "); } foreach (var Item in NFDet.ITENS) { SQL.AppendLine("Insert Into NFeSItens "); SQL.AppendLine(" ( NFeSId , "); SQL.AppendLine(" Quantidade , "); SQL.AppendLine(" CodigoAtividade , "); SQL.AppendLine(" Servico , "); SQL.AppendLine(" ValorUnitario , "); SQL.AppendLine(" ValorTotal , "); SQL.AppendLine(" ImpostoRetido , "); SQL.AppendLine(" Aliquota , "); SQL.AppendLine(" Active , "); SQL.AppendLine(" DateInsert , "); SQL.AppendLine(" DateUpdate "); SQL.AppendLine(" ) "); SQL.AppendLine("Values ( " + Id + " , "); SQL.AppendLine(" '" + Functions.NoQuote(Item.Quantidade) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(Item.CodigoAtividade) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(Item.Servico) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(Item.ValorUnitario) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(Item.ValorTotal) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(Item.ImpostoRetido) + "' , "); SQL.AppendLine(" '" + Functions.NoQuote(Item.Aliquota) + "' , "); SQL.AppendLine(" 1 , "); SQL.AppendLine(" '" + Functions.DateTimeBr().ToString("yyyy-MM-dd HH:mm:ss") + "' , "); SQL.AppendLine(" '" + Functions.DateTimeBr().ToString("yyyy-MM-dd HH:mm:ss") + "' "); SQL.AppendLine(" )"); SQL.AppendLine(" "); } if ((NFDet.FATURA.Length > 0 | NFDet.ITENS.Length > 0) & SQL.ToString().Length > 0) { Functions.Conn.Insert(SQL.ToString()); } } }catch (Exception ex) { throw ex; } }
public NFeSRequestPreview Issue(NFeSRequest NFeS) { try { ValidateIssue(NFeS); //Objetos da Nota Fiscal: var Taker = new TakerDomain().Get <Takers>(NFeS.TakerId); var Company = new CompanyDomain().Get <Companys>(CompanyDomain.Type.Company, NFeS.CompanyId); var CFPS = new CFPSDomain().Get <CFPS>(NFeS.CFPSId); var TaxpayerActivities = new TaxpayerActivitiesDomain().Get(NFeS.TaxpayerActivitiesId); var ShippingCompany = new ShippingCompany(); if (NFeS.ShippingCompanyId > 0) { ShippingCompany = new ShippingCompanyDomain().Get <ShippingCompany>(NFeS.ShippingCompanyId); } //Nota Fiscal: var NFeSRequest = new Models.Models.NFeSStructure.NFeSIssueRequest.tbnfd(); var NotaFiscal = new Models.Models.NFeSStructure.NFeSIssueRequest.tbnfdNfd() { numeronfd = Homologation.NumberNF, codseriedocumento = Homologation.Serie, codnaturezaoperacao = CFPS.CFPSCod, codigocidade = Homologation.CityCod, inscricaomunicipalemissor = Homologation.IM, dataemissao = Functions.DateTimeBr().ToString("dd/MM/yyyy"), razaotomador = Taker.Name, nomefantasiatomador = Taker.NameFantasy, enderecotomador = Taker.Street, numeroendereco = Taker.Number, cidadetomador = Taker.City, estadotomador = Taker.State, paistomador = Homologation.Country, fonetomador = Taker.Telephone, faxtomador = Taker.Telephone, ceptomador = Taker.CEP, bairrotomador = Taker.Neighborhood, emailtomador = Taker.Email, tppessoa = Taker.TypePerson, cpfcnpjtomador = Taker.CPF_CNPJ, inscricaoestadualtomador = Taker.RG_IE, inscricaomunicipaltomador = Taker.IM, observacao = NFeS.Note, razaotransportadora = Functions.IIf(ShippingCompany.Name), cpfcnpjtransportadora = Functions.IIf(ShippingCompany.CPF_CNPJ), pis = Homologation.PIS, cofins = Homologation.COFINS, csll = Homologation.CSLL, irrf = Homologation.IRRF, inss = Homologation.INSS, descdeducoesconstrucao = string.Empty, totaldeducoesconstrucao = string.Empty, tributadonomunicipio = string.Empty, vlroutros = string.Empty, numerort = string.Empty, codigoseriert = string.Empty, dataemissaort = string.Empty, fatorgerador = Functions.DateTimeBr().Month + "/" + Functions.DateTimeBr().Year, enderecotransportadora = Functions.IIf(ShippingCompany.Street) + "," + Functions.IIf(ShippingCompany.Neighborhood) + "," + Functions.IIf(ShippingCompany.City) + "," + Functions.IIf(ShippingCompany.State), }; //Faturas: NotaFiscal.tbfatura = new Models.Models.NFeSStructure.NFeSIssueRequest.tbnfdNfdFatura[NFeS.Invoices.Count]; for (int X = 0; X < NFeS.Invoices.Count; X++) { NFeSRequestInvoices Invoice = NFeS.Invoices[X]; NotaFiscal.tbfatura[X] = new Models.Models.NFeSStructure.NFeSIssueRequest.tbnfdNfdFatura { numfatura = Invoice.Number.ToString(), vencimentofatura = DateTime.Parse(Invoice.Maturity).ToString("dd/MM/yyyy"), valorfatura = Invoice.Value.ToString() }; } //Serviços: NotaFiscal.tbservico = new Models.Models.NFeSStructure.NFeSIssueRequest.tbnfdNfdServico[NFeS.Itens.Count]; for (int X = 0; X < NFeS.Itens.Count; X++) { NFeSRequestItens Item = NFeS.Itens[X]; Services Services = new ServiceDomain().Get <Services>(Item.ServicesId); NotaFiscal.tbservico[X] = new Models.Models.NFeSStructure.NFeSIssueRequest.tbnfdNfdServico { quantidade = Item.Amount.ToString(), descricao = Services.Description, codatividade = TaxpayerActivities.CNAE, valorunitario = Item.Value.ToString(), aliquota = TaxpayerActivities.Aliquot.ToString(), impostoretido = CFPS.TaxWithheld }; } NFeSRequest.nfd = NotaFiscal; string XmlRPS = API.Send(API.GetCity(Company.City), Homologation.CPF, Homologation.Password, int.Parse(Homologation.CityCod), this.Assign(NFeSRequest)); if (Functions.XmlFunctions.IsXml(XmlRPS)) { //Enviando o RPS para receber a NFSe(5 tentativas)// int Cont = 0; string XmlAuthorized = string.Empty; //Primeira tentativa XmlAuthorized = API.Receive(API.GetCity(Company.City), Homologation.CPF, Homologation.Password, Homologation.IM, XmlRPS); bool Auth = Functions.XmlFunctions.IsXml(XmlAuthorized); while (!Auth & Cont <= 5) { XmlAuthorized = API.Receive(API.GetCity(Company.City), Homologation.CPF, Homologation.Password, Homologation.IM, XmlRPS); Auth = Functions.XmlFunctions.IsXml(XmlAuthorized); Cont++; System.Threading.Thread.Sleep(5000); } if (Functions.XmlFunctions.IsXml(XmlAuthorized)) { var NFeSAuthorized = Functions.XmlFunctions.StringXmlForClass <Models.Models.NFeSStructure.NFeSProcessingResult.tbnfd>(XmlAuthorized); string XmlUrl = API.GetUrl(API.City.Serra, int.Parse(Homologation.CityCod), int.Parse(NFeSAuthorized.nfdok.NewDataSet.NOTA_FISCAL.NumeroNota), int.Parse(NFeSAuthorized.nfdok.NewDataSet.NOTA_FISCAL.CodigoSerie), Homologation.IM); if (Functions.XmlFunctions.IsXml(XmlUrl)) { var NFeSUrl = Functions.XmlFunctions.StringXmlForClass <Models.Models.NFeSStructure.NFeSPreview.util>(XmlUrl); string PDF = Download(NFeSUrl.urlNfd); //Salvando no banco os dados da nota fiscal Save(Taker, Company, CFPS, ShippingCompany, NFeSAuthorized, NFeSUrl, XmlAuthorized, PDF); //Enviando email para o tomador SendEmail(Taker, Company, NFeSAuthorized, NFeSUrl); return(new NFeSRequestPreview(NFeSUrl.urlNfd, PDF)); } else { throw new InternalProgramException(XmlUrl); } } else { throw new InternalProgramException(XmlAuthorized); } } else { throw new InternalProgramException(XmlRPS); } } catch (Exception ex) { throw ex; } }
protected override void Seed(WebShopDBContext context) { var manufacturer1 = new Manufacturer() { ManufacturerName = "Adidas" }; var manufacturer2 = new Manufacturer() { ManufacturerName = "Nike" }; var manufacturer3 = new Manufacturer() { ManufacturerName = "Converse" }; context.Manufacturers.Add(manufacturer1); context.Manufacturers.Add(manufacturer2); context.Manufacturers.Add(manufacturer3); var shippingCompany1 = new ShippingCompany() { ShippingCompanyName = "DB Schenker", ShippingCostPercentage = 0.04M }; var shippingCompany2 = new ShippingCompany() { ShippingCompanyName = "DHL", ShippingCostPercentage = 0.02M }; var shippingCompany3 = new ShippingCompany() { ShippingCompanyName = "Maersk", ShippingCostPercentage = 0.2M }; context.ShippingCompanies.Add(shippingCompany1); context.ShippingCompanies.Add(shippingCompany2); context.ShippingCompanies.Add(shippingCompany3); Category category1 = new Category() { CategoryName = "Jeans", Description = "hiqh quality jeans in all sizes and shapes!" }; Category category2 = new Category() { CategoryName = "Jackets", Description = "Jackets in high quality, for both summer and winter conditions!" }; Category category3 = new Category() { CategoryName = "Shoes", Description = "Shoes ranging from all types of manufacturers!" }; Category category4 = new Category() { CategoryName = "Shirts", Description = "Shirts for the summernights and hot days!" }; Category category5 = new Category() { CategoryName = "Accessories", Description = "Accessories for the ones that like to put some bling in their life!" }; context.Categories.Add(category1); context.Categories.Add(category2); context.Categories.Add(category3); context.Categories.Add(category4); context.Categories.Add(category5); Product prod1 = new Product() { ProductName = "Adidas one", DiscountPercentage = 0, Stock = 50, UnitPrice = 499, Manufacturer = manufacturer1, Category = category3 }; Product prod2 = new Product() { ProductName = "Adidas two", DiscountPercentage = 0, Stock = 50, UnitPrice = 699, Manufacturer = manufacturer1, Category = category3 }; Product prod3 = new Product() { ProductName = "Nikey one", DiscountPercentage = 0, Stock = 50, UnitPrice = 599, Manufacturer = manufacturer2, Category = category3 }; Product prod4 = new Product() { ProductName = "Nikey Two", DiscountPercentage = 0, Stock = 50, UnitPrice = 899, Manufacturer = manufacturer2, Category = category3 }; Product prod5 = new Product() { ProductName = "Converse one", DiscountPercentage = 0, Stock = 50, UnitPrice = 999, Manufacturer = manufacturer3, Category = category3 }; context.Products.Add(prod1); context.Products.Add(prod2); context.Products.Add(prod3); context.Products.Add(prod4); context.Products.Add(prod5); /* passing the WebShopDBContext instance * into the seed method of the base class */ base.Seed(context); }
public async Task <ActionResult> Create([Bind(Include = "Id,CartNumber,SaleDate,NumberOfItems,BuyerId,BuyerEmailId,CartAmount,ItemsAmount,ShippingAmount")] CartVM cartVM) { cartVM.TransactionVMs = Session["Transactions"] as List <TransactionVM>; if (ModelState.IsValid) { bool error = false; if (cartVM.CartAmount <= 0) { ModelState.AddModelError(nameof(cartVM.CartAmount), "The overall value must be larger than 0"); error = true; } if (cartVM.ItemsAmount <= 0) { ModelState.AddModelError(nameof(cartVM.ItemsAmount), "The value of items in the cart must be larger than 0"); error = true; } if (cartVM.ShippingAmount < 0) { ModelState.AddModelError(nameof(cartVM.ShippingAmount), "The shipping cost for items in the cart cannot be less than 0."); error = true; } if (cartVM.PayPalAmount < 0) { ModelState.AddModelError(nameof(cartVM.PayPalAmount), "The PayPal fees cannot be less than 0."); error = true; } if (cartVM.CartAmount < cartVM.ItemsAmount) { ModelState.AddModelError(nameof(cartVM.ItemsAmount), "The value of items cannot be larger than the overall value for the cart"); error = true; } if (cartVM.CartAmount < cartVM.ShippingAmount) { ModelState.AddModelError(nameof(cartVM.ShippingAmount), "The shipping amount cannot be larger than the overall value for the cart"); error = true; } if (cartVM.CartAmount < cartVM.PayPalAmount) { ModelState.AddModelError(nameof(cartVM.PayPalAmount), "The PayPal fees cannot be larger than the overall value for the cart"); error = true; } if (error) { var list = db.UserRecords.OrderBy(u => u.HDBUserName).ToList(); cartVM.Buyers = new SelectList(list.Where(u => (u.UserType & UserRecord.UserTypes.Buyer) == UserRecord.UserTypes.Buyer), "Id", "HDBUserName"); cartVM.Sellers = new SelectList(list.Where(u => (u.UserType & UserRecord.UserTypes.Seller) == UserRecord.UserTypes.Seller), "Id", "HDBUserName"); return(View(cartVM)); } Cart cart = new Cart() { CartNumber = cartVM.CartNumber, SaleDate = cartVM.SaleDate, NumberOfItems = cartVM.NumberOfItems, NumberOfSellers = cartVM.NumberOfSellers, BuyerId = cartVM.BuyerId, TotalValue = cartVM.CartAmount, ItemCost = cartVM.ItemsAmount, ShippingCost = cartVM.ShippingAmount, PayPalFees = cartVM.PayPalAmount, }; cart.Buyer = db.UserRecords.SingleOrDefault(r => r.Id == cartVM.BuyerId); cart.BuyerEmailId = cart.Buyer.PreferredEmailId; cart.ComputeFees(cartVM.TransactionVMs.Count); db.Carts.Add(cart); await db.SaveChangesAsync(); LogRecord cartLR = new LogRecord() { DateTime = DateTime.Now, RecordType = Utilities.RecordType.New, Guid = typeof(Cart).GUID, RecordId = cart.Id }; db.LogRecords.Add(cartLR); await db.SaveChangesAsync(); ShippingCompany shipCompany = db.ShippingCompanies.FirstOrDefault(s => s.Name == "Unknown"); foreach (var tr in cartVM.TransactionVMs) { await AddTransaction(tr, cart.Id, shipCompany); } return(RedirectToAction("Index")); } return(View(cartVM)); }
public bool Addcompany(ShippingCompany C) { string query = "INSERT INTO SHIPPING_COMPANY VALUES('" + C.NAME + "', '" + C.EMAIL + "', '" + C.PHONE + "', " + C.SHIPPING_FEES + ")"; return(db.ExecuteNonQuery(query) != 0); }