public async Task <ActionResult> Create(FormCollection f) { var userId = ((Account)Session[Constant.UserAdminSession]).UserId; var billImport = new BillImportRequest { BillImportType = BillImportType.AwaitingApproval, CreationTime = DateTime.Now, TotalPrice = 0, UserId = userId }; billImport.Id = await billImportDAO.CreateBillImportAsync(billImport); var billImportInfos = new List <BillImportInfo>(); int count = int.Parse(Request.Cookies["RowCount"].Value); for (int i = 0; i < count; i++) { long productId = long.Parse(f[$"MaSP_{i}"]); long price = long.Parse(f[$"DonGiaNhap_{i}"]); int numberImport = int.Parse(f[$"SoLuongNhap_{i}"]); billImportInfos.Add(new BillImportInfo { BillImportId = billImport.Id, Price = price, ProductId = productId, NumberImport = numberImport }); } bool result = await billImportDAO.CreateBillImportInfoAsync(billImportInfos, billImport.Id); if (result) { TempData["SaveBillImport"] = "Tạo phiếu nhập hàng thành công!"; return(RedirectToAction("Index")); } return(View("Create")); }
public async Task <long> CreateBillImportAsync(BillImportRequest billImportRequest) { var billImport = new BillImport { UserId = billImportRequest.UserId, TotalPrice = billImportRequest.TotalPrice, BillImportType = billImportRequest.BillImportType, CreationTime = billImportRequest.CreationTime }; dbContext.BillImports.Add(billImport); await dbContext.SaveChangesAsync(); return(billImport.Id); }