public ActionResult Edit([Bind(Include = "ID,TransDate,TransAmount,Source,Memo")] Transaction transaction)
 {
     if (ModelState.IsValid)
     {
         db.Entry(transaction).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(transaction));
 }
Пример #2
0
        public void InsertOrUpdateTransactions(IReadOnlyCollection <Transaction> transactions)
        {
            lock (_lockObject)
            {
                var transactionsToInsert = new List <TransactionDb>();
                foreach (var transaction in transactions)
                {
                    var existingTransaction = _transactionDbContext.Transactions.Find(transaction.Id);
                    if (existingTransaction == null)
                    {
                        transactionsToInsert.Add(Convert(transaction));
                    }
                    else
                    {
                        _transactionDbContext.Entry(existingTransaction).CurrentValues.SetValues(transaction);
                    }
                }

                _transactionDbContext.Transactions.AddRange(transactionsToInsert);

                _transactionDbContext.SaveChanges();
            }
        }
Пример #3
0
 public void Update(TransactionOrder order)
 {
     _dbSet.Attach(order);
     _context.Entry(order).State = EntityState.Modified;
     _context.SaveChanges();
 }
Пример #4
0
        public async Task <ResultObject> UpdateArrival(T_Arrival_Header arr)
        {
            var resultObj = new ResultObject {
                RowAffected = -1, ObjectValue = arr
            };

            using (var context = new TransactionDbContext(contextOptions))
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        context.Entry(arr).State = EntityState.Modified;

                        MySqlParameter[] sqlParams = new MySqlParameter[] {
                            new MySqlParameter("strId", arr.Id),
                            new MySqlParameter("strArrivalNo", arr.ArrivalNo),
                            new MySqlParameter("strArrivalDate", arr.ArrivalDate),
                            new MySqlParameter("strRawMatTypeId", arr.RawMatTypeId),
                            new MySqlParameter("strVendorId", arr.VendorId),
                            new MySqlParameter("strArrivalTypeId", arr.ArrivalTypeId),
                            new MySqlParameter("strPurchaseOrderNo", arr.PurchaseOrderNo),
                            new MySqlParameter("strDocRefNo", arr.DocRefNo),
                            new MySqlParameter("strDocRefDate", arr.DocRefDate),
                            new MySqlParameter("strArrivalRemark", arr.ArrivalRemark),
                            new MySqlParameter("strCompanyCode", arr.CompanyCode),
                            new MySqlParameter("strIs_Active", arr.Is_Active),
                            new MySqlParameter("strUpdated_By", arr.Updated_By)
                        };

                        resultObj.RowAffected = await context.Database.ExecuteSqlCommandAsync("call sp_arrival_hdr_update(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", parameters : sqlParams);

                        if (arr.ArrivalDetails.Count > 0)
                        {
                            MySqlParameter[] sqlParams2;

                            foreach (T_Arrival_Detail arrdtl in arr.ArrivalDetails)
                            {
                                switch (arrdtl.RecordFlag)
                                {
                                case 0:     //delete row

                                    sqlParams2 = new MySqlParameter[] {
                                        new MySqlParameter("strId", arrdtl.Id),
                                        new MySqlParameter("strArrivalId", arrdtl.ArrivalId),
                                        new MySqlParameter("strLineNo", arrdtl.LineNo),
                                        new MySqlParameter("strPoLineNo", arrdtl.PoLineNo),
                                        new MySqlParameter("strMaterialId", arrdtl.MaterialId),
                                        new MySqlParameter("strCompanyCode", arrdtl.CompanyCode),
                                        new MySqlParameter("strDelete_By", arrdtl.Created_By)
                                    };

                                    resultObj.RowAffected += await context.Database.ExecuteSqlCommandAsync("call sp_arrival_dtl_delete(?, ?, ?, ?, ?, ?, ?)", parameters : sqlParams2);

                                    break;

                                case 1:     //no change (only update line no)

                                    sqlParams2 = new MySqlParameter[] {
                                        new MySqlParameter("strId", arrdtl.Id),
                                        new MySqlParameter("strLineNo", arrdtl.LineNo)
                                    };

                                    resultObj.RowAffected += await context.Database.ExecuteSqlCommandAsync("call sp_arrival_dtl_updateline(?, ?)", parameters : sqlParams2);

                                    break;

                                case 2:     //new row

                                    sqlParams2 = new MySqlParameter[] {
                                        new MySqlParameter("strArrivalId", arr.Id),
                                        new MySqlParameter("strLineNo", arrdtl.LineNo),
                                        new MySqlParameter("strPoLineNo", arrdtl.PoLineNo),
                                        new MySqlParameter("strMaterialId", arrdtl.MaterialId),
                                        new MySqlParameter("strMaterialCode", arrdtl.MaterialCode),
                                        new MySqlParameter("strMaterialName", arrdtl.MaterialName),
                                        new MySqlParameter("strMaterialDesc", arrdtl.MaterialDesc),
                                        new MySqlParameter("strOrderQty", arrdtl.OrderQty),
                                        new MySqlParameter("strRecvQty", arrdtl.RecvQty),
                                        new MySqlParameter("strLotNo", arrdtl.LotNo),
                                        new MySqlParameter("strLotDate", arrdtl.LotDate),
                                        new MySqlParameter("strDetailRemark", arrdtl.DetailRemark),
                                        new MySqlParameter("strGenLabelStatus", arrdtl.GenLabelStatus),
                                        new MySqlParameter("strNoOfLabel", arrdtl.NoOfLabel),
                                        new MySqlParameter("strCompanyCode", arrdtl.CompanyCode),
                                        new MySqlParameter("strIs_Active", arrdtl.Is_Active),
                                        new MySqlParameter("strCreated_By", arr.Updated_By)
                                    };

                                    resultObj.RowAffected += await context.Database.ExecuteSqlCommandAsync("call sp_arrival_dtl_insert(@`strId`, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", parameters : sqlParams2);

                                    break;

                                case 3:     //Edit Qty

                                    sqlParams2 = new MySqlParameter[] {
                                        new MySqlParameter("strId", arrdtl.Id),
                                        new MySqlParameter("strArrivalId", arrdtl.ArrivalId),
                                        new MySqlParameter("strLineNo", arrdtl.LineNo),
                                        new MySqlParameter("strPoLineNo", arrdtl.PoLineNo),
                                        new MySqlParameter("strMaterialId", arrdtl.MaterialId),
                                        new MySqlParameter("strOrderQty", arrdtl.OrderQty),
                                        new MySqlParameter("strCompanyCode", arrdtl.CompanyCode),
                                        new MySqlParameter("strCreated_By", arrdtl.Created_By)
                                    };

                                    resultObj.RowAffected += await context.Database.ExecuteSqlCommandAsync("call sp_arrival_dtl_update(?, ?, ?, ?, ?, ?, ?, ?)", parameters : sqlParams2);

                                    break;

                                default:
                                    break;
                                }
                            }
                        }

                        transaction.Commit();

                        return(resultObj);
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw ex;
                    }
                }
            }
        }