/// <summary> /// Completes the unit of work transaction and persists all changed data. /// </summary> public virtual async Task Complete() { try { if (PayrollContext != null) { await PayrollContext.SaveChangesAsync(); } DbContextTransaction.Commit(); } catch (DbEntityValidationException dbEx) { DbContextTransaction.Rollback(); //foreach ( // var validationError in // dbEx.EntityValidationErrors.SelectMany(validationErrors => validationErrors.ValidationErrors)) //{ // _logger.Error(string.Format("Property: {0} Error: {1}", validationError.PropertyName, // validationError.ErrorMessage)); //} throw; } _completed = true; }
/// <summary> /// 删除任务 /// </summary> /// <param name="id"></param> /// <returns></returns> public bool DeleteTask(int id, ref string errMsg) { try { using (JDJS_WMS_DB_USEREntities wms = new JDJS_WMS_DB_USEREntities()) { using (System.Data.Entity.DbContextTransaction mytran = wms.Database.BeginTransaction()) { try { var work = wms.JDJS_WMS_Order_Process_Scheduling_Table.Where(r => r.ID == id).FirstOrDefault(); if (work == null) { mytran.Rollback(); errMsg = "该任务不存在"; return(false); } DateTime time = Convert.ToDateTime(work.StartTime); TimeSpan timespan = Convert.ToDateTime(work.EndTime) - Convert.ToDateTime(work.StartTime); var works = wms.JDJS_WMS_Order_Process_Scheduling_Table.Where(r => r.CncID == work.CncID && r.isFlag == 1 && r.StartTime > time); foreach (var item in works) { DateTime startTime = Convert.ToDateTime(item.StartTime); item.StartTime = startTime - timespan; DateTime endTime = Convert.ToDateTime(item.EndTime); item.EndTime = endTime - timespan; } wms.JDJS_WMS_Order_Process_Scheduling_Table.Remove(work); wms.SaveChanges(); mytran.Commit(); errMsg = "ok"; return(true); } catch (Exception ex) { errMsg = ex.Message; mytran.Rollback(); return(false); } } } } catch (Exception ex) { errMsg = ex.Message; return(false); } }
public async Task <int> Handle(CreateScopeCommand request, CancellationToken cancellationToken) { Scope scope = request.ToScope(); using (System.Data.Entity.DbContextTransaction transaction = _context.Database.BeginTransaction()) { try { _context.Scopes.Add(scope); await _context.SaveChangesAsync(); System.Collections.Generic.IEnumerable <ScopeScopeClaim> scopeClaims = request.ScopeClaims.Select(id => new ScopeScopeClaim { ScopeClaimId = id, ScopeId = scope.Id, CreatedBy = request.CreatedBy, CreatedOn = request.CreatedOn, Deleted = false }); _context.ScopeScopeClaims.AddRange(scopeClaims); await _context.SaveChangesAsync(); transaction.Commit(); } catch { transaction.Rollback(); } return(scope.Id); } }
public ActionResult Index() { //transaction if EF using (System.Data.Entity.DbContextTransaction dbTrans = context.Database.BeginTransaction()) { try { Notifications notif1 = new Notifications { Message = "msg1", NotifType = 1, TimeStamp = DateTime.Now }; context.Notifications.Add(notif1); context.SaveChanges(); context.Database.ExecuteSqlCommand(@"update Notifications set Message='msg1 updated' where Id=" + notif1.Id); context.SaveChanges(); dbTrans.Commit(); } catch (Exception ex) { dbTrans.Rollback(); } } return(View(context.Notifications.ToList())); }
public void ProcessRequest(HttpContext context) { using (JDJS_WMS_DB_USEREntities entities = new JDJS_WMS_DB_USEREntities()) { using (System.Data.Entity.DbContextTransaction db = entities.Database.BeginTransaction()) { try { var form = context.Request.Form; for (int i = 0; i < form.Count; i++) { var id = int.Parse(form[i]); var row = entities.JDJS_WMS_Quality_ManualInput_Measurement_Table.Where(r => r.ID == id); if (row.Count() > 0) { entities.JDJS_WMS_Quality_ManualInput_Measurement_Table.Remove(row.FirstOrDefault()); } } entities.SaveChanges(); db.Commit(); context.Response.Write("ok"); } catch (Exception ex) { db.Rollback(); context.Response.Write(ex.Message); } } } }
public string AddMapping(MappingModel model) { string table_Name = model.Table_Name; string FormID = model.FormID; int Approved = model.Approved; string Message = "OK"; using (SysContext db = new SysContext()) { System.Data.Entity.DbContextTransaction tran = db.Database.BeginTransaction(); try { fl_MappingForm entity_fl_MappingForm = new fl_MappingForm(); entity_fl_MappingForm.FormNo = FormID; entity_fl_MappingForm.Table_Name = table_Name; entity_fl_MappingForm.Approved = Approved; entity_fl_MappingForm.ApprovedDate = DateTime.Now; entity_fl_MappingForm.TemplateUrl = ""; entity_fl_MappingForm.CreatedUser = LoginInfo.UserID; entity_fl_MappingForm.ModifiedUser = LoginInfo.UserID; entity_fl_MappingForm.ResetCreated(); db.fl_MappingForm.Add(entity_fl_MappingForm); db.SaveChanges(); tran.Commit(); } catch { tran.Rollback(); Message = "Error"; } } return(Message); }
public JsonResult UpdateActiveService(string memberId, string Id, bool isActive) { var db = new DBContext(); using (System.Data.Entity.DbContextTransaction ContextTransaction = db.Database.BeginTransaction()) { try { string decrptMemId = Decrypt.DecryptMe(memberId); long MembId = long.Parse(decrptMemId); string decrptSlID = Decrypt.DecryptMe(Id); long SlId = long.Parse(decrptSlID); var updateServiceStatus = db.TBL_WHITELABLE_SERVICE.Where(x => x.SL_NO == SlId && x.MEMBER_ID == MembId).FirstOrDefault(); if (updateServiceStatus != null) { updateServiceStatus.ACTIVE_SERVICE = isActive; db.Entry(updateServiceStatus).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); ContextTransaction.Commit(); return(Json(new { Result = "true" })); } return(Json(new { Result = "true" })); } catch (Exception ex) { ContextTransaction.Rollback(); return(Json(new { Result = "false" })); } } }
public bool DeleteProject(int projectId) { using (System.Data.Entity.DbContextTransaction dbTran = this.Database.BeginTransaction()) { try { //Delete all files of this project from DB var sql = @"DELETE FROM ProjectFiles WHERE ProjectFiles.ProjectID = {0} "; this.Database.ExecuteSqlCommand(sql, projectId); //Delete all members of this project from DB var sql2 = @"DELETE FROM ProjectMembers WHERE ProjectID = {0} "; this.Database.ExecuteSqlCommand(sql2, projectId); // Delete all TextSegment of this project from DB var sql3 = @"DELETE FROM TextSegment WHERE ProjectID = {0} "; this.Database.ExecuteSqlCommand(sql3, projectId); //Delete this project var sql4 = @"DELETE FROM Projects WHERE Id = {0} "; this.Database.ExecuteSqlCommand(sql4, projectId); this.SaveChanges(); dbTran.Commit(); return(true); } catch (Exception e) { dbTran.Rollback(); Debug.WriteLine("Error: " + e.Message); return(false); } } }
public string Add(DocumentInfoModel item) { using (ScorelinkEntities db = new ScorelinkEntities()) { using (System.Data.Entity.DbContextTransaction dbTran = db.Database.BeginTransaction()) { try { var docInfo = new DocumentInfo { FileUID = item.FileUID, FileName = item.FileName, FilePath = item.FilePath, CreateBy = item.CreateBy, CreateDate = DateTime.Parse(item.CreateDate) }; db.DocumentInfoes.Add(docInfo); db.SaveChanges(); //var lastuser = db.Users.Select(x => x.UserId).Max(); dbTran.Commit(); return("OK"); } catch (Exception ex) { dbTran.Rollback(); return(ex.ToString()); } } } }
static void MyTransaction() { using (LibraryEntities db = new LibraryEntities()) { using (System.Data.Entity.DbContextTransaction dbTran = db.Database.BeginTransaction()) { try { string tmp = ""; for (int i = 0; i < 101; i++) { tmp += i.ToString(); } Author author = new Author { FirstName = tmp, LastName = "TESTTRANSACTION" }; db.Author.Add(author); //db.Author.Remove(author); db.SaveChanges(); dbTran.Commit(); } catch (Exception ex) { dbTran.Rollback(); } } } }
///end-add student-class //begin add studentinfo&&student-class public int Addstudentandclass(List <class_student> c_studl, List <StudInfo1> studentl) { Exercise_ERContainer cn = new Exercise_ERContainer(); System.Data.Entity.DbContextTransaction tr = cn.Database.BeginTransaction(); try { foreach (StudInfo1 student in studentl) { if (cn.StudInfo1Set.Find(student.studentid) == null) { cn.StudInfo1Set.Add(student); } } foreach (class_student c_stud in c_studl) { cn.class_student.Add(c_stud); } cn.SaveChanges(); tr.Commit(); return(1); } //catch (DbEntityValidationException ex) catch (Exception ex) { Console.WriteLine(ex.Message); tr.Rollback(); return(0); } }
private void ClearDataBase(global::DataAccess.Context.AppContext dbContext) { // create transaction to clear DataBase using (System.Data.Entity.DbContextTransaction transaction = dbContext.Database.BeginTransaction()) { try { // disable all constraints in the database dbContext.Database.ExecuteSqlCommand("EXEC sp_MSforeachtable \"ALTER TABLE ? NOCHECK CONSTRAINT all\""); // gets all tables' names string[] tableNames = dbContext.Database.SqlQuery <string>("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_NAME NOT LIKE '%Migration%'").ToArray(); // clear out data in all tables foreach (string tableName in tableNames) { dbContext.Database.ExecuteSqlCommand($"DELETE FROM [{tableName}];"); } // enable all constraints in the database dbContext.Database.ExecuteSqlCommand("EXEC sp_MSforeachtable @command1=\"print '?'\", @command2=\"ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all\""); // commit transaction transaction.Commit(); } catch { // rollback transtaction on any error transaction.Rollback(); throw; } } }
public JsonResult DeactivateBankDetails(string id) { var db = new DBContext(); using (System.Data.Entity.DbContextTransaction ContextTransaction = db.Database.BeginTransaction()) { try { long idval = long.Parse(id); var bankdeactive = db.TBL_SETTINGS_BANK_DETAILS.Where(x => x.SL_NO == idval).FirstOrDefault(); bankdeactive.ISDELETED = 1; bankdeactive.DELETED_DATE = System.DateTime.Now; bankdeactive.DELETED_BY = 0; db.Entry(bankdeactive).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); ContextTransaction.Commit(); return(Json(new { Result = "true" })); } catch (Exception ex) { ContextTransaction.Rollback(); return(Json(new { Result = "false" })); } } }
public JsonResult TransactionDecline(string trandate = "", string TransationStatus = "", string slnval = "") { var db = new DBContext(); using (System.Data.Entity.DbContextTransaction ContextTransaction = db.Database.BeginTransaction()) { try { //var db = new DBContext(); long sln = long.Parse(slnval); var transinfo = db.TBL_BALANCE_TRANSFER_LOGS.Where(x => x.SLN == sln).FirstOrDefault(); //transinfo.REQUEST_DATE = Convert.ToDateTime(trandate); transinfo.STATUS = "Decline"; transinfo.APPROVAL_DATE = DateTime.Now; transinfo.APPROVAL_TIME = DateTime.Now; transinfo.APPROVED_BY = "Power Admin"; db.Entry(transinfo).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); ContextTransaction.Commit(); return(Json(new { Result = "true" })); } catch (Exception ex) { ContextTransaction.Rollback(); return(Json(new { Result = "false " })); } } }
// POST: api/PaymentHistories public HttpResponseMessage PostPaymentHistory(PaymentHistory paymentHistory) { using (System.Data.Entity.DbContextTransaction transaction = db.Database.BeginTransaction()) { try { //https://www.codeproject.com/Articles/14403/Generating-Unique-Keys-in-Net paymentHistory.TranscationId = DateTime.Now.ToString().GetHashCode().ToString("x"); paymentHistory.CreatedDate = DateTime.Now; db.PaymentHistories.Add(paymentHistory); db.SaveChanges(); var userdetails = db.Users.Where(u => u.Id == paymentHistory.UserId).FirstOrDefault(); userdetails.Balance_Amount = userdetails.Balance_Amount - paymentHistory.Amount; db.Entry(userdetails).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); transaction.Commit(); } catch (Exception) { transaction.Rollback(); } } return(Request.CreateResponse(HttpStatusCode.OK, new { paymentHistory.Amount, paymentHistory.CreatedDate, paymentHistory.TranscationId, Routes = db.Routes.Where(r => r.RouteId == paymentHistory.RouteId).Select(r => new { r.From, r.To }), exitlocation = db.TollPlazas.Where(tp => tp.Id == paymentHistory.ExitLocId).Select(tp => tp.Location) })); }
public virtual bool CreateNewProject(Project newProject, IEnumerable <int> listMember) { using (System.Data.Entity.DbContextTransaction dbTran = this.Database.BeginTransaction()) { try { this.Projects.Add(newProject); this.SaveChanges(); int?newId = newProject.Id; foreach (var id in listMember) { var sql = @"INSERT INTO ProjectMembers VALUES({0}, {1}, 0)"; this.Database.ExecuteSqlCommand(sql, newId, id); } dbTran.Commit(); return(true); } catch (Exception e) { dbTran.Rollback(); Debug.WriteLine("Error: " + e.Message); return(false); } } }
public bool UpdateProject(Project project, IEnumerable <int> newlyInsertedIDList, IEnumerable <int> deletedIDList) { using (System.Data.Entity.DbContextTransaction dbTran = this.Database.BeginTransaction()) { try { foreach (var memberId in newlyInsertedIDList) { var sql = @"INSERT INTO ProjectMembers VALUES({0}, {1}, 0)"; this.Database.ExecuteSqlCommand(sql, project.Id, memberId); } foreach (var memberId in deletedIDList) { var sql = @"DELETE FROM ProjectMembers WHERE ProjectMembers.ProjectID = {0} AND ProjectMembers.UserID = {1}"; this.Database.ExecuteSqlCommand(sql, project.Id, memberId); } this.Entry(project).State = System.Data.Entity.EntityState.Modified; this.SaveChanges(); dbTran.Commit(); return(true); } catch (Exception e) { dbTran.Rollback(); Debug.WriteLine("Error: " + e.Message); return(false); } } }
public HttpResponseMessage Post([FromUri] int id, [FromBody] tbl_Customer customer) { System.Data.Entity.DbContextTransaction transaction = entities.Database.BeginTransaction(); tbl_Card card = new tbl_Card(); try { tbl_Card c = entities.tbl_Card.Where(ca => ca.Customer_Id == customer.Customer_Id).FirstOrDefault(); if (c != null) { return(Request.CreateErrorResponse(HttpStatusCode.NotAcceptable, "Customer already activated.")); } proc_ActivateCustomer_Result rslt = entities.proc_ActivateCustomer(customer.Customer_Id).FirstOrDefault(); card.Customer_Id = customer.Customer_Id; card.Card_Number = RandomDigits(10); card.Valid_till = DateTime.Today.AddYears(2).Date; card.Card_Type = customer.Card_Type; card.Total_credit = customer.Card_Type == "Gold" ? 50000 : 100000; card.credit_used = 0; card.Card_cost = customer.Card_Type == "Gold" ? 1000 : 2000; card.Status = "Activated"; tbl_Admin admin = entities.tbl_Admin.Where(a => a.Admin_Id == id).FirstOrDefault(); card.ApprovedBy = id; entities.tbl_Card.Add(card); entities.SaveChanges(); proc_ActivateCard_Result result = entities.proc_ActivateCard(customer.Customer_Id).FirstOrDefault(); transaction.Commit(); return(Request.CreateResponse(HttpStatusCode.Created, card)); } catch (Exception) { transaction.Rollback(); return(Request.CreateErrorResponse(HttpStatusCode.NotAcceptable, "Could not add card")); } }
public HttpResponseMessage Post(int id, string prodName, decimal amt) { System.Data.Entity.DbContextTransaction transaction = entities.Database.BeginTransaction(); tbl_Transaction tran = new tbl_Transaction(); try { tbl_Product prod = entities.tbl_Product.Where(p => p.Product_Name == prodName).FirstOrDefault(); int cardId = (int)entities.tbl_EMI.Where(e => e.EMI_Id == id).FirstOrDefault().Card_Id; tran.EMI_Id = id; tran.Product_Name = prod.Product_Name; tran.Transaction_Date = DateTime.Today; tran.Transaction_Amount = amt; tran.cardId = cardId; entities.tbl_Transaction.Add(tran); entities.SaveChanges(); transaction.Commit(); proc_updateCardAmountEmiPayment_Result result = entities.proc_updateCardAmountEmiPayment(id, cardId, amt).FirstOrDefault(); return(Request.CreateResponse(HttpStatusCode.Created, tran)); } catch (Exception) { transaction.Rollback(); return(Request.CreateErrorResponse(HttpStatusCode.NotAcceptable, "transaction failed")); } }
/// <summary> /// Save Users /// </summary> /// <param name="user"></param> /// <returns></returns> public int SaveUser(User user) { using (SMLDBEntities context = new SMLDBEntities()) { using (System.Data.Entity.DbContextTransaction transaction = context.Database.BeginTransaction()) { try { UserTable tblUser = new UserTable() { UserID = user.UserID, Email = user.Email, Password = user.Password, UserName = user.UserName }; context.UserTables.Add(tblUser); context.SaveChanges(); transaction.Commit(); user.UserID = tblUser.UserID; return(user.UserID); } catch (Exception) { transaction.Rollback(); return(0); } } } }
/// <summary> /// Update Users /// </summary> /// <param name="user"></param> /// <returns></returns> public int UpdateUser(User user) { using (SMLDBEntities context = new SMLDBEntities()) { using (System.Data.Entity.DbContextTransaction transaction = context.Database.BeginTransaction()) { try { UserTable tblUser = context.UserTables.Where(t => t.UserID == user.UserID).FirstOrDefault(); if (tblUser != null && tblUser.UserID > 0) { tblUser.UserID = user.UserID; tblUser.Email = user.Email ?? tblUser.Email; tblUser.Password = user.Password ?? tblUser.Password; tblUser.UserName = user.UserName ?? tblUser.UserName; } context.SaveChanges(); transaction.Commit(); user.UserID = tblUser.UserID; return(user.UserID); } catch (Exception) { transaction.Rollback(); return(0); } } } }
/// <summary> /// Save Song /// </summary> /// <param name="song"></param> /// <returns></returns> public int SaveSong(Song song) { using (SMLDBEntities context = new SMLDBEntities()) { using (System.Data.Entity.DbContextTransaction transaction = context.Database.BeginTransaction()) { try { SongTable tblUser = new SongTable() { SongID = song.SongID, SongName = song.SongName, Artist = song.Artist, Lyrics = song.Lyrics, UserId = song.UserId }; context.SongTables.Add(tblUser); context.SaveChanges(); transaction.Commit(); song.SongID = tblUser.SongID; return(song.SongID); } catch (Exception) { transaction.Rollback(); return(0); } } } }
public void ProcessRequest(HttpContext context) { int PlanId = int.Parse(context.Request["MaintenacneID"]); int enable = int.Parse(context.Request["MaintenanceEnable"]); using (JDJS_WMS_DB_USEREntities wms = new JDJS_WMS_DB_USEREntities()) { using (System.Data.Entity.DbContextTransaction mytran = wms.Database.BeginTransaction()) { try { var plan = wms.JDJS_WMS_Device_Accuracy_Verification_Plan.Where(r => r.ID == PlanId); foreach (var item in plan) { item.isFlag = enable; } wms.SaveChanges(); mytran.Commit(); } catch { mytran.Rollback(); } } } context.Response.Write("ok"); }
/// <summary> /// Update Song /// </summary> /// <param name="song"></param> /// <returns></returns> public int UpdateSong(Song song) { using (SMLDBEntities context = new SMLDBEntities()) { using (System.Data.Entity.DbContextTransaction transaction = context.Database.BeginTransaction()) { try { SongTable tblSong = context.SongTables.Where(t => t.SongID == song.SongID).FirstOrDefault(); if (tblSong != null && tblSong.SongID > 0) { tblSong.SongID = song.SongID; tblSong.SongName = song.SongName ?? tblSong.SongName; tblSong.Artist = song.Artist ?? tblSong.Artist; tblSong.Lyrics = song.Lyrics ?? tblSong.Lyrics; tblSong.UserId = song.UserId > 0 ? song.UserId : tblSong.UserId; } context.SaveChanges(); transaction.Commit(); song.SongID = tblSong.SongID; return(song.SongID); } catch (Exception) { transaction.Rollback(); return(0); } } } }
/// <summary> /// Save Change Request Data /// </summary> /// <param name="sodChangeMaster"></param> /// <param name="sodChangeDetails"></param> /// <returns></returns> public Int64 SaveChangeRequest(SODEmployeeChangeRequestMaster sodChangeMaster, SODEmployeeChangeRequestDetails sodChangeDetails) { Int64 id = 0; using (System.Data.Entity.DbContextTransaction dbTran = _context.Database.BeginTransaction()) { try { _context.SODEmployeeChangeRequestMaster.Add(sodChangeMaster); _context.SaveChanges(); //Get Max ID id = _context.SODEmployeeChangeRequestMaster.DefaultIfEmpty().Max(x => x == null ? 1 : x.ReqId); //Add Id in Details sodChangeDetails.ReqId = id; _context.SODEmployeeChangeRequestDetails.Add(sodChangeDetails); //_context.SaveChanges(); _context.SaveChanges(); dbTran.Commit(); } catch (Exception ex) { //Rollback transaction if exception occurs dbTran.Rollback(); id = -1; throw; } } return(id); }
public static string Generater() { PCMSDBContext dbContext = new PCMSDBContext(); PcmsId id = new PcmsId(); using (System.Data.Entity.DbContextTransaction dbTran = dbContext.Database.BeginTransaction()) { try { dbContext.PcmsIds.Add(id); dbContext.SaveChanges(); id.KEY = String.Format("P{0:D6}", id.ID); dbContext.SaveChanges(); dbTran.Commit(); } catch (Exception e) { log.Error(e); dbTran.Rollback(); } dbTran.Dispose(); } return(id.KEY); }
/// <summary> /// 治具异常报备 /// </summary> /// <param name="id">工序id</param> /// <returns></returns> public bool AbnormalSubmit(int id, ref string errMsg) { try { using (JDJS_WMS_DB_USEREntities wms = new JDJS_WMS_DB_USEREntities()) { var processes = wms.JDJS_WMS_Order_Fixture_Manager_Table.Where(r => r.ProcessID == id); using (System.Data.Entity.DbContextTransaction mytran = wms.Database.BeginTransaction()) { try { foreach (var item in processes) { item.FixtureFinishPerpareNumber = 0; } wms.SaveChanges(); errMsg = "ok"; mytran.Commit(); return(true); } catch (Exception ex) { mytran.Rollback(); errMsg = ex.Message; return(false); } } } } catch (Exception ex) { errMsg = ex.Message; return(false); } }
public JsonResult RejectKYCDocument(string Id) { var db = new DBContext(); using (System.Data.Entity.DbContextTransaction ContextTransaction = db.Database.BeginTransaction()) { long MemID = long.Parse(Id); var getdocinfo = db.TBL_MASTER_MEMBER.Where(x => x.MEM_ID == MemID).FirstOrDefault(); if (getdocinfo != null) { getdocinfo.KYC_VERIFIED = false; getdocinfo.KYC_VERIFIED_USER = long.Parse(Session["UserId"].ToString()); getdocinfo.VERIFICATION_DATE = System.DateTime.Now; db.Entry(getdocinfo).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); ContextTransaction.Commit(); return(Json(new { Result = "true" })); } else { ContextTransaction.Rollback(); return(Json(new { Result = "false" })); } } //string decrptMemId = Decrypt.DecryptMe(Id); }
public void ProcessRequest(HttpContext context) { { int OrderID = int.Parse(context.Request["orderId"]); System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); List <string> str = new List <string>(); using (JDJS_WMS_DB_USEREntities wms = new JDJS_WMS_DB_USEREntities()) { using (System.Data.Entity.DbContextTransaction date = wms.Database.BeginTransaction()) { try { List <int> processid = new List <int>(); var process = wms.JDJS_WMS_Order_Process_Info_Table.Where(r => r.OrderID == OrderID && r.sign != 0); foreach (var item in process) { if (!processid.Contains(Convert.ToInt32(item.ProcessID))) { processid.Add(Convert.ToInt32(item.ProcessID)); } } processid.Sort(); List <int> ProcessId = new List <int>(); foreach (var item in processid) { var processed = wms.JDJS_WMS_Order_Process_Info_Table.Where(r => r.OrderID == OrderID && r.sign != 0 && r.ProcessID == item); ProcessId.Add(Convert.ToInt32(processed.FirstOrDefault().ID)); } foreach (var item in ProcessId) { List <int> CncID = new List <int>(); var mach = wms.JDJS_WMS_Order_Process_Scheduling_Table.Where(r => r.ProcessID == item && r.isFlag != 0); foreach (var real in mach) { if (!CncID.Contains(Convert.ToInt32(real.CncID))) { CncID.Add(Convert.ToInt32(real.CncID)); } } var fix = wms.JDJS_WMS_Order_Fixture_Manager_Table.Where(r => r.ProcessID == item); fix.FirstOrDefault().FixtureNumber = CncID.Count(); wms.SaveChanges(); str.Add(CncID.Count().ToString()); } wms.SaveChanges(); date.Commit(); } catch (Exception ex) { date.Rollback(); context.Response.Write(ex.Message); } } } var json = serializer.Serialize(str); context.Response.Write("ok"); } }
public void ProcessRequest(HttpContext context) { var processId = int.Parse(context.Request["processId"]); var time = Convert.ToDateTime(context.Request["time"]); using (JDJS_WMS_DB_USEREntities wms = new JDJS_WMS_DB_USEREntities()) { using (System.Data.Entity.DbContextTransaction mytran = wms.Database.BeginTransaction()) { try { var processInfo = wms.JDJS_WMS_Order_Process_Info_Table.Where(r => r.ID == processId).FirstOrDefault(); processInfo.Jig_Expected_Completion_Time = time; wms.SaveChanges(); mytran.Commit(); context.Response.Write("ok"); } catch (Exception ex) { mytran.Rollback(); context.Response.Write(ex.Message); } } } }