protected override void Dispose(bool disposing) { if (disposing) { db.Dispose(); } base.Dispose(disposing); }
public ActionResult SaveData(RequestVM D) { bool status = false; string mes = ""; var w = (from y in databaseManager.sUsers where y.UserID.ToString() == User.Identity.Name select new { y.PlantNo }).FirstOrDefault(); var wn = databaseManager.sPlants.Where(x => x.PlantNo == w.PlantNo).FirstOrDefault(); string s1 = w.PlantNo.ToString(); string s2 = string.Concat(s1 + "1000000"); int reqno = Convert.ToInt32(s2); var maxreqno = (from n in databaseManager.FrdRequestMasters where n.PlantID == w.PlantNo select n.ReqID).DefaultIfEmpty(reqno).Max(); var maxrNo = maxreqno + 1; int v = maxrNo; using (LIVEEntities ddd = new LIVEEntities()) { FrdRequestMaster dbo = new FrdRequestMaster(); { dbo.ReqID = maxrNo; dbo.PlantID = D.PlantID; dbo.DeptID = D.DeptID; dbo.ReqDate = DateTime.Today; dbo.CustomerID = Convert.ToInt32(User.Identity.Name); dbo.RefNo = D.RefNo; dbo.Remarks = D.Remarks; dbo.Status = "I"; dbo.CreateDate = DateTime.Now; dbo.CreateBy = User.Identity.Name; }; ddd.FrdRequestMasters.Add(dbo); foreach (var i in D.reqdtl) { FrdRequestDetail obd = new FrdRequestDetail(); { obd.PlantID = D.PlantID; obd.ReqID = maxrNo; obd.ItemID = i.ItemID; obd.Quantity = i.Quantity; obd.UnitPrice = 0; obd.TotalAmt = 0; ddd.FrdRequestDetails.Add(obd); } } ddd.SaveChanges(); status = true; ddd.Dispose(); ModelState.Clear(); } return(new JsonResult { Data = new { status = status, mes = mes, v = v } }); }
public ActionResult SaveUpdate(ChangeVM D) { bool status = false; string mes = ""; var w = (from y in databaseManager.sUsers where y.UserID.ToString() == User.Identity.Name select new { y.UserID }).FirstOrDefault(); try { using (var transaction = databaseManager.Database.BeginTransaction()) { if (ModelState.IsValid) { var result = databaseManager.sUsers.SingleOrDefault(b => b.UserID == w.UserID); if (result != null) { result.UserPass = D.NewPass; result.UserPin = D.UserPass; } databaseManager.SaveChanges(); transaction.Commit(); status = true; databaseManager.Dispose(); ModelState.Clear(); } else { status = false; transaction.Rollback(); } return(new JsonResult { Data = new { status = status, mes = mes } }); } } catch (Exception ex) { string mess = ex.Message; return(Json(new { status = "error", message = "Error Generate" })); } }
public ActionResult MyTransaction(TransactionVM D) { bool status = false; string mes = ""; var w = (from y in databaseManager.sUsers where y.UserID.ToString() == User.Identity.Name select new { y.PlantNo }).FirstOrDefault(); var wn = databaseManager.sPlants.Where(x => x.PlantNo == w.PlantNo).FirstOrDefault(); string s1 = w.PlantNo.ToString(); string s2 = string.Concat(s1 + "7000000"); int reqno = Convert.ToInt32(s2); var maxreqno = (from n in databaseManager.FrdPurchases where n.PlantID == w.PlantNo select n.ReceivedTranNo).DefaultIfEmpty(reqno).Max(); var maxrNo = maxreqno + 1; string Code = string.Concat("REC" + maxreqno); int v = maxrNo; try { using (var transaction = databaseManager.Database.BeginTransaction()) { if (ModelState.IsValid) { FrdPurchase dbo = new FrdPurchase(); { dbo.ReceivedTranNo = maxrNo; dbo.PlantID = D.PlantID; dbo.ReceivedTranNo = maxrNo; dbo.TranDate = DateTime.Today; dbo.RefOrderNo = D.RefOrderNo; dbo.LCNo = D.LCNo; dbo.LocalForeign = D.LocalForeign; dbo.SupplierID = D.SupplierID; dbo.IndentNo = D.IndentNo; dbo.TotalQty = D.TotalQty; dbo.TotalPrice = D.TotalPrice; dbo.Remarks = D.Remarks; dbo.Status = "REC"; dbo.RefInvoice = D.RefInvoice; dbo.CreateBy = User.Identity.Name; dbo.CreateDate = DateTime.Now; }; databaseManager.FrdPurchases.Add(dbo); foreach (var i in D.reqdtl) { FrdPurchaseInfo obd = new FrdPurchaseInfo(); { obd.PlantID = D.PlantID; obd.TranRefNo = maxrNo; obd.ItemCode = i.ItemCode; obd.Qty = i.Qty; obd.UnitPrice = i.UnitPrice; databaseManager.FrdPurchaseInfoes.Add(obd); } if (i.ItemCode != 0 && D.PlantID != 0) { databaseManager.spStockProduct(D.PlantID, i.ItemCode, 1, Convert.ToInt32(i.Qty), i.Qty, i.UnitPrice); } } var result = databaseManager.FrdReceiveMasters.SingleOrDefault(b => b.ReqRecID == D.RefOrderNo); if (result != null) { result.Status = "COM"; //databaseManager.SaveChanges(); } databaseManager.SaveChanges(); transaction.Commit(); status = true; databaseManager.Dispose(); ModelState.Clear(); } else { status = false; transaction.Rollback(); } return(new JsonResult { Data = new { status = status, mes = mes, v = v } }); } } catch (Exception ex) { string mess = ex.Message; return(Json(new { status = "error", message = "Error Generate" })); } }
public ActionResult SaveReceived(ReceiveVM D) { bool status = false; string mes = ""; var w = (from y in databaseManager.sUsers where y.UserID.ToString() == User.Identity.Name select new { y.PlantNo }).FirstOrDefault(); var wn = databaseManager.sPlants.Where(x => x.PlantNo == w.PlantNo).FirstOrDefault(); string s1 = w.PlantNo.ToString(); string s2 = string.Concat(s1 + "1000000"); int reqno = Convert.ToInt32(s2); var maxreqno = (from n in databaseManager.FrdReceiveMasters where n.PlantID == w.PlantNo select n.ReqRecID).DefaultIfEmpty(reqno).Max(); var maxrNo = maxreqno + 1; int v = maxrNo; try { // using (LIVEEntities ddd = new LIVEEntities()) using (var transaction = databaseManager.Database.BeginTransaction()) { if (ModelState.IsValid) { FrdReceiveMaster dbo = new FrdReceiveMaster(); { dbo.ReqRecID = maxrNo; dbo.PlantID = D.PlantID; dbo.DeptID = D.DeptID; dbo.RecDate = DateTime.Today; dbo.ReqID = D.ReqID; //dbo.RefNo = D.RefNo; dbo.SupplierID = D.SupplierID; dbo.UserNote = D.UserNote; dbo.TypeCode = D.TypeCode; if (D.TypeCode == 20) { dbo.AppBy = "XXXXX"; dbo.AppFlag = "O"; dbo.Status = "PEN"; } else { dbo.AppBy = "NA"; dbo.AppFlag = "N"; dbo.Status = "COM"; } dbo.CreateDate = DateTime.Now; dbo.CreateBy = User.Identity.Name; }; databaseManager.FrdReceiveMasters.Add(dbo); foreach (var i in D.itemdtl) { FrdReceiveDetail obd = new FrdReceiveDetail(); { obd.PlantID = D.PlantID; obd.ReqRecID = maxrNo; obd.ItemID = i.ItemID; obd.Quantity = i.Quantity; obd.UnitPrice = i.UnitPrice; databaseManager.FrdReceiveDetails.Add(obd); } } var result = databaseManager.FrdRequestMasters.SingleOrDefault(b => b.ReqID == D.ReqID); if (result != null) { result.Status = "A"; databaseManager.SaveChanges(); } databaseManager.SaveChanges(); transaction.Commit(); status = true; databaseManager.Dispose(); ModelState.Clear(); } else { status = false; transaction.Rollback(); } return(new JsonResult { Data = new { status = status, mes = mes, v = v } }); } } catch (Exception ex) { string mess = ex.Message; return(Json(new { status = "error", message = "Error Generate" })); } }