private async Task <IActionResult> CreateInvoiceAsync([FromBody] CartDto cart, int orderid) { if (cart == null || cart.cartItems == null) //if no item in cart, return not found; { return(NotFound()); } if (!_context.Cards.Any(c => c.Id == cart.card_id)) { return(NotFound("This account does not exist, card_id :" + cart.card_id + " !")); } if (!_context.Orders.Any(o => o.Id == orderid)) { return(NotFound("This order does not exist, card_id :" + cart.card_id + " !")); } var customerGst = cart.customer_gst; var currentOrder = _context.Orders.Where(o => o.Id == orderid).FirstOrDefault(); var branch = _context.Orders.Where(o => o.Id == orderid).FirstOrDefault().Branch; var shippingMethod = _context.Orders.Where(o => o.Id == orderid).FirstOrDefault().ShippingMethod; var freightTax = cart.freight - Math.Round((decimal)(cart.freight / (1 + (decimal?)customerGst)), 4); var newInvoice = new Invoice(); newInvoice.Branch = branch; newInvoice.CardId = cart.card_id; newInvoice.Price = (decimal?)cart.sub_total; newInvoice.ShippingMethod = shippingMethod; newInvoice.Tax = (decimal?)cart.tax + freightTax; newInvoice.Freight = Math.Round((decimal)(cart.freight / (1 + (decimal?)customerGst)), 4); newInvoice.Total = (decimal?)(cart.total); // + cart.freight); newInvoice.CommitDate = DateTime.Now; newInvoice.ShippingMethod = (byte)cart.shipping_method; _context.Add(newInvoice); _context.SaveChanges(); var invoiceNumber = newInvoice.Id; currentOrder.InvoiceNumber = invoiceNumber; newInvoice.InvoiceNumber = invoiceNumber; _context.SaveChanges(); IActionResult a = await inputSalesItem(cart.cartItems, invoiceNumber, customerGst); return(Ok(new { orderid, invoiceNumber, newInvoice.Total })); }
public IActionResult checkpw([FromBody] JsonPatchDocument <LoginDto> patchMylogin, int userId) { if (patchMylogin == null) { return(BadRequest()); } var accountToPatch = _context.Cards.FirstOrDefault(c => c.Id == userId); if (accountToPatch == null) { return(NotFound()); } var newAccountToPatch = new LoginDto() { id = accountToPatch.Id, password = accountToPatch.Password }; patchMylogin.ApplyTo(newAccountToPatch, ModelState); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } accountToPatch.Password = newAccountToPatch.password; MD5 md5Hash = MD5.Create(); byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(accountToPatch.Password)); StringBuilder sBuilder = new StringBuilder(); for (int i = 0; i < data.Length; i++) { sBuilder.Append(data[i].ToString("x2")); } string md5password = sBuilder.ToString().ToUpper(); accountToPatch.Password = md5password; _context.Cards.Update(accountToPatch); _context.SaveChanges(); //return NoContent(); return(Ok(new { password = newAccountToPatch.password, md5password = md5password })); }