public async Task Calling_SaveChangesAsyncWithHistory_ShouldCallOnSaveCallback() { // ARRANGE var birthday = new ImportantDate { Description = "Birthday", Date = new DateTime(2000, 1, 1) }; var person = new Person { Name = "John", ImportantDates = new List <ImportantDate> { birthday } }; var postSaveAction = new Mock <IPostSaveAction <ApplicationContext> >(); // ACT var success = false; await DatabaseFixture.ExecuteTest(async (context, time) => { context.People.Add(person); await context.SaveChangesAsyncWithHistory(); }, (provider) => postSaveAction.Object); // ASSERT postSaveAction.Verify(x => x.Handle(It.IsAny <ApplicationContext>(), It.Is <IList <Audit> >((o) => o.Count == 2))); }
public async Task Calling_SaveChangesAsyncWithHistory_ShouldCallOnSaveCallback() { // ARRANGE var birthday = new ImportantDate { Description = "Birthday", Date = new DateTime(2000, 1, 1) }; var person = new Person { Name = "John", ImportantDates = new List <ImportantDate> { birthday } }; // ACT var success = false; await DatabaseFixture.ExecuteTest(async (context, time) => { context.People.Add(person); await context.SaveChangesAsyncWithHistory((c, list) => { c.ShouldBe(context); list.Count.ShouldBe(2); success = true; }); }); // ASSERT success.ShouldBe(true); }
public async Task Calling_SaveChangesAsyncWithHistory_ShouldStoreTransactionIdAcrossTableChanges() { // ARRANGE var birthday = new ImportantDate { Description = "Birthday", Date = new DateTime(2000, 1, 1) }; var person = new Person { Name = "John", ImportantDates = new List <ImportantDate> { birthday } }; await DatabaseFixture.ExecuteTest(async (context, options) => { context.People.Add(person); // ACT await context.SaveChangesAsyncWithHistory(); // ASSERT var auditItem = context.Set <Audit>().Where(x => true).ToList().ToDictionary(x => x.TableName); auditItem["People"].TransactionId.ShouldBe(options.TransactionId()); auditItem["ImportantDates"].TransactionId.ShouldBe(options.TransactionId()); }, null); }
public async Task Calling_SaveChangesAsyncWithHistory_ShouldPersistAssociatedData() { // ARRANGE var birthday = new ImportantDate { Description = "Birthday", Date = new DateTime(2000, 1, 1) }; var person = new Person { Name = "John", ImportantDates = new List <ImportantDate> { birthday } }; var postSaveAction = new Mock <IPostSaveAction <ApplicationContext> >(); await DatabaseFixture.ExecuteTest(async (context, options) => { context.People.Add(person); // ACT await context.SaveChangesAsyncWithHistory(); // ASSERT var auditItem = context.Set <Audit>().Where(x => true).ToList().ToDictionary(x => x.TableName); // Validate the Person auditItem["People"].Action.ShouldBe("Added"); auditItem["People"].CreatedBy.ShouldBe("TestUser"); auditItem["People"].Client.ShouldBe("TestApp"); auditItem["People"].CreateDate.ShouldBe(options.CurrentDateTime()); var changes = JsonConvert.DeserializeObject <Dictionary <string, AuditEntry.Change> >(auditItem["People"].Data); changes["name"].NewValue.ShouldBe("John"); changes["name"].OldValue.ShouldBe(null); var key = JObject.Parse(auditItem["People"].RowId); var personId = Guid.Parse(key["id"].ToString()); personId.ShouldNotBe(Guid.Empty); // Validate the important date auditItem["ImportantDates"].Action.ShouldBe("Added"); auditItem["ImportantDates"].CreatedBy.ShouldBe("TestUser"); auditItem["ImportantDates"].Client.ShouldBe("TestApp"); auditItem["ImportantDates"].CreateDate.ShouldBe(options.CurrentDateTime()); changes = JsonConvert.DeserializeObject <Dictionary <string, AuditEntry.Change> >( auditItem["ImportantDates"] .Data); changes["personId"].NewValue.ShouldBe(personId.ToString()); DateTime.Parse(changes["date"].NewValue.ToString()).ShouldBe(birthday.Date); changes["date"].OldValue.ShouldBeNull(); changes["description"].NewValue.ShouldBe("Birthday"); changes["description"].OldValue.ShouldBeNull(); key = JObject.Parse(auditItem["ImportantDates"].RowId); Guid.Parse(key["id"].ToString()).ShouldNotBe(Guid.Empty); }, provider => postSaveAction.Object); }
public void AddToList(string eventOfThisDate, string date, int isAnnually) { ImportantDate importantDate = new ImportantDate(); importantDate.Event = eventOfThisDate; importantDate.Date = date; importantDate.IsAnnually = isAnnually; importantDates.Add(importantDate); }
public void UpdateData(int id, string eventOfThisDate, string date, int isAnnually) { ImportantDate importantDate = GetElementById(id); importantDate.Date = date; importantDate.Event = eventOfThisDate; importantDate.IsAnnually = isAnnually; dataBase.Update(importantDate); StandardActions(); }
public void AddNewEvent(string eventOfThisDate, string date, int isAnnually) { ImportantDate importantDate = new ImportantDate(); importantDate.Event = eventOfThisDate; importantDate.Date = date; importantDate.IsAnnually = isAnnually; dataBase.Insert(importantDate); StandardActions(); }
public async Task <ActionResult> DeleteConfirmed(int id) { ImportantDate importantDate = await _context.ImportantDates.FindAsync(id); _context.ImportantDates.Remove(importantDate); await _context.SaveChangesAsync(); return(RedirectToAction <ImportantDatesController>(c => c.Index()) .WithSuccess("Important Date Deleted.")); }
private async void AutomaticFillingAsync() { await Task.Run(() => { ImportantDate importantDate = new ImportantDate(); importantDate.Event = "Новый год"; importantDate.Date = "01.01.1900"; importantDate.IsAnnually = 1; dataBase.Insert(importantDate); importantDate.Event = "Рождество"; importantDate.Date = "07.01.1900"; importantDate.IsAnnually = 1; dataBase.Insert(importantDate); importantDate.Event = "День всех влюблённых"; importantDate.Date = "14.02.1900"; importantDate.IsAnnually = 1; dataBase.Insert(importantDate); importantDate.Event = "День защитника Отечества"; importantDate.Date = "23.02.1900"; importantDate.IsAnnually = 1; dataBase.Insert(importantDate); importantDate.Event = "Международный женский день"; importantDate.Date = "08.03.1900"; importantDate.IsAnnually = 1; dataBase.Insert(importantDate); importantDate.Event = "Праздник Весны и Труда"; importantDate.Date = "01.05.1900"; importantDate.IsAnnually = 1; dataBase.Insert(importantDate); importantDate.Event = "День Победы"; importantDate.Date = "09.05.1945"; importantDate.IsAnnually = 1; dataBase.Insert(importantDate); importantDate.Event = "День России"; importantDate.Date = "12.06.1992"; importantDate.IsAnnually = 1; dataBase.Insert(importantDate); importantDate.Event = "День знаний"; importantDate.Date = "01.09.1984"; importantDate.IsAnnually = 1; dataBase.Insert(importantDate); importantDate.Event = "День народного единства"; importantDate.Date = "04.11.2005"; importantDate.IsAnnually = 1; dataBase.Insert(importantDate); importantDate.Event = "День матери"; importantDate.Date = "24 25 26 27 28 29 30.11.1998"; importantDate.IsAnnually = 1; dataBase.Insert(importantDate); }); }
public async Task <ActionResult> Create(ImportantDateCreateModel model) { if (!ModelState.IsValid) { return(View(model)); } var importantDate = new ImportantDate { DueDate = model.DueDate, Comments = model.Comments }; _context.ImportantDates.Add(importantDate); await _context.SaveChangesAsync(); return(RedirectToAction <ImportantDatesController>(c => c.Index()) .WithSuccess("Important Date Created.")); }
public async Task <ActionResult> Edit(ImportantDateEditModel model) { if (!ModelState.IsValid) { return(View(model)); } ImportantDate importantDate = await _context.ImportantDates.SingleOrDefaultAsync(i => i.Id == model.Id); if (importantDate == null) { return(RedirectToAction <ImportantDatesController>(c => c.Index()) .WithError("Could not load Important Date")); } importantDate.DueDate = model.DueDate; importantDate.Comments = model.Comments; await _context.SaveChangesAsync(); return(RedirectToAction <ImportantDatesController>(c => c.Index()) .WithSuccess("Important Date Updated.")); }
private void BondSchedule_Load(object sender, EventArgs e) { using (var db = new TestEntities()) { ImportantDate iDate = db.ImportantDates.Find(strjobnumber); BindingSource bs1 = new BindingSource(); var row = (from r in db.ImportantDates where (r.BaseID == strjobnumber) select r); var list = row.ToList(); //var query = (from r in db.ImportantDates // where (r.BaseID == strjobnumber) // select r; // var list = query.ToList(); dgvBaseline.DataSource = list; dgvBaseline.Refresh(); BindingSource bs2 = new BindingSource(); var row2 = (from r2 in db.BondActuals where (r2.BaseID == strjobnumber) select r2); var list2 = row2.ToList(); dgvActuals.DataSource = list2; dgvActuals.Refresh(); // var query = from c in db.ImportantDates.Find(strjobnumber); // var dates = query.ToList(); //if (iDate != null) //{ // dgvBaseline.DataSource = iDate; //} var lotlist = db.ActiveJobs .Where(b => b.BaseID.Contains(strjobnumber.Substring(0, 8))); int p = lotlist.Count(); ActiveJob[] array1 = lotlist.ToArray(); for (int i = 0; i < p; i++) { string name = "chk" + i; string lot = array1[i].BaseID.Substring(11, 2); chklistbox.Items.Add("Lot" + lot); } if (iDate != null) { if (iDate.StartAssy == null) { dtpAssy.Value = DateTime.Now; lblStartAssembly.BackColor = Color.Red; lblStartAssembly.ForeColor = Color.White; bassy = false; } else { dtpAssy.MinDate = new System.DateTime(); dtpAssy.Value = iDate.StartAssy.Value; dtStartAssembly = iDate.StartAssy.Value; } if (iDate.DesRel == null) { dtpDataRls.Value = DateTime.Now; lblDataRelease.BackColor = Color.Red; lblDataRelease.ForeColor = Color.White; bdesrel = false; } else { dtpDataRls.MinDate = new System.DateTime(); dtpDataRls.Value = iDate.DesRel.Value; dtDataRelease = iDate.DesRel.Value; } if (iDate.StartFab == null) { dtpFab.Value = DateTime.Now; lblStartFab.BackColor = Color.Red; lblStartFab.ForeColor = Color.White; bfab = false; } else { dtpFab.MinDate = new System.DateTime(); dtpFab.Value = iDate.StartFab.Value; dtStartFab = iDate.StartFab.Value; } if (iDate.HeatTreat == null) { dtpHt.Value = DateTime.Now; lblHeatTreat.BackColor = Color.Red; lblHeatTreat.ForeColor = Color.White; bht = false; } else { dtpHt.MinDate = new System.DateTime(); dtpHt.Value = iDate.HeatTreat.Value; dtHeatTreat = iDate.HeatTreat.Value; } if (iDate.StartMachining == null) { dtpMach.Value = DateTime.Now; lblStartMachining.BackColor = Color.Red; lblStartMachining.ForeColor = Color.White; bsmach = false; } else { dtpMach.MinDate = new System.DateTime(); dtpMach.Value = iDate.StartMachining.Value; dtStartMachining = iDate.StartMachining.Value; } if (iDate.RecvMaterial == null) { dtpReceive.Value = DateTime.Now; lblReceiveMaterial.BackColor = Color.Red; lblReceiveMaterial.ForeColor = Color.White; bmaterial = false; } else { dtpReceive.MinDate = new System.DateTime(); dtpReceive.Value = iDate.RecvMaterial.Value; dtReceiveMaterial = iDate.RecvMaterial.Value; } if (iDate.MachComp == null) { dtpMachComp.Value = DateTime.Now; lblMachineComplete.BackColor = Color.Red; lblMachineComplete.ForeColor = Color.White; bmachcomp = false; } else { dtpMachComp.MinDate = new System.DateTime(); dtpMachComp.Value = iDate.MachComp.Value; dtMachineComplete = iDate.MachComp.Value; } if (iDate.RdyChk == null) { dtpRdyChk.Value = DateTime.Now; lblReadyCheck.BackColor = Color.Red; lblReadyCheck.ForeColor = Color.White; bchk = false; } else { dtpRdyChk.MinDate = new System.DateTime(); dtpRdyChk.Value = iDate.RdyChk.Value; dtReadyCheck = iDate.RdyChk.Value; } if (iDate.RdySrc == null) { dtpRdySrc.Value = DateTime.Now; lblReadySource.BackColor = Color.Red; lblReadySource.ForeColor = Color.White; bsrc = false; } else { dtpRdySrc.MinDate = new System.DateTime(); dtpRdySrc.Value = iDate.RdySrc.Value; dtReadySource = iDate.RdySrc.Value; } // dtpSrc.Value = iDate.RdySrc.Value; } else { lblStartAssembly.BackColor = Color.Red; lblStartAssembly.ForeColor = Color.White; lblDataRelease.BackColor = Color.Red; lblDataRelease.ForeColor = Color.White; lblStartFab.BackColor = Color.Red; lblStartFab.ForeColor = Color.White; lblHeatTreat.BackColor = Color.Red; lblHeatTreat.ForeColor = Color.White; lblStartMachining.BackColor = Color.Red; lblStartMachining.ForeColor = Color.White; lblReceiveMaterial.BackColor = Color.Red; lblReceiveMaterial.ForeColor = Color.White; lblMachineComplete.BackColor = Color.Red; lblMachineComplete.ForeColor = Color.White; lblReadyCheck.BackColor = Color.Red; lblReadyCheck.ForeColor = Color.White; lblReadySource.BackColor = Color.Red; lblReadySource.ForeColor = Color.White; } } }
private void btnSubmit_Click(object sender, EventArgs e) { object[] items = chklistbox.CheckedItems.OfType <object>().ToArray(); var target = "Lot"; string baseid = ""; string jobnumber = strjobnumber.Substring(0, 8); if (chklistbox.CheckedItems.Count == 0) { MessageBox.Show("You didn't check anything dope. TRY AGAIN"); } else { target += strjobnumber.Substring(11, 2); bool has = items.Contains(target); if (has == true) { string lots = ""; TestEntities db = new TestEntities(); for (int o = 0; o < items.Length; o++) { baseid = jobnumber; baseid += " / " + items[o].ToString().Substring(3, 2); ImportantDate iDate = db.ImportantDates.Find(strjobnumber); dtDataRelease = dtpDataRls.Value.Date; dtReceiveMaterial = dtpReceive.Value.Date; dtStartFab = dtpFab.Value.Date; dtHeatTreat = dtpHt.Value.Date; dtStartMachining = dtpMach.Value.Date; dtMachineComplete = dtpMachComp.Value.Date; dtStartAssembly = dtpAssy.Value.Date; dtReadyCheck = dtpRdyChk.Value.Date; dtReadySource = dtpRdySrc.Value.Date; try { if (iDate == null) { iDate = new ImportantDate(); iDate.BaseID = strjobnumber; if (bmaterial == true) { iDate.RecvMaterial = dtReceiveMaterial; } else { iDate.RecvMaterial = null; } if (bfab == true) { iDate.StartFab = dtStartFab; } else { iDate.StartFab = null; } if (bht == true) { iDate.HeatTreat = dtHeatTreat; } else { iDate.HeatTreat = null; } if (bsmach == true) { iDate.StartMachining = dtStartMachining; } else { iDate.StartMachining = null; } if (bassy == true) { iDate.StartAssy = dtStartAssembly; } else { iDate.StartAssy = null; } if (bmachcomp == true) { iDate.MachComp = dtMachineComplete; } else { iDate.MachComp = null; } if (bchk == true) { iDate.RdyChk = dtReadyCheck; } else { iDate.RdyChk = null; } if (bsrc == true) { iDate.RdySrc = dtReadySource; } else { iDate.RdySrc = null; } if (bdesrel == true) { iDate.DesRel = dtDataRelease; } else { iDate.DesRel = null; } //iDate.BaseID = strjobnumber; //iDate.RecvMaterial = dtReceiveMaterial; //iDate.StartFab = dtStartFab; //iDate.HeatTreat = dtHeatTreat; //iDate.StartMachining = dtStartMachining; //iDate.StartAssy = dtStartAssembly; //iDate.MachComp = dtMachineComplete; //iDate.RdyChk = dtReadyCheck; //iDate.RdySrc = dtReadySource; //iDate.DesRel = dtDataRelease; db.ImportantDates.Add(iDate); db.SaveChanges(); } else { iDate.BaseID = strjobnumber; if (bmaterial == true) { iDate.RecvMaterial = dtReceiveMaterial; } else { iDate.RecvMaterial = null; } if (bfab == true) { iDate.StartFab = dtStartFab; } else { iDate.StartFab = null; } if (bht == true) { iDate.HeatTreat = dtHeatTreat; } else { iDate.HeatTreat = null; } if (bsmach == true) { iDate.StartMachining = dtStartMachining; } else { iDate.StartMachining = null; } if (bassy == true) { iDate.StartAssy = dtStartAssembly; } else { iDate.StartAssy = null; } if (bmachcomp == true) { iDate.MachComp = dtMachineComplete; } else { iDate.MachComp = null; } if (bchk == true) { iDate.RdyChk = dtReadyCheck; } else { iDate.RdyChk = null; } if (bsrc == true) { iDate.RdySrc = dtReadySource; } else { iDate.RdySrc = null; } if (bdesrel == true) { iDate.DesRel = dtDataRelease; } else { iDate.DesRel = null; } // db.ImportantDates.Add(iDate); db.SaveChanges(); } } catch (DbEntityValidationException f) { foreach (var eve in f.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } finally { this.dgvActuals.Refresh(); this.dgvActuals.Refresh(); } //impdate.BaseID; } MessageBox.Show("Successfully Updated " + items.Length + " items. GREAT JOB!!!"); } } //dtDataRelease = dtpDataRls.Value.Date; //dtReceiveMaterial = dtpReceive.Value.Date; //dtStartFab = dtpFab.Value.Date; //dtHeatTreat = dtpHt.Value.Date; //dtStartMachining = dtpMach.Value.Date; //dtMachineComplete = dtpMachComp.Value.Date; //dtStartAssembly = dtpAssy.Value.Date; //dtReadyCheck = dtpRdyChk.Value.Date; //dtReadySource = dtpRdySrc.Value.Date; //using (var db = new TestEntities()) //{ // Link link = db.Links.Find(jobnumber); // if (link != null) // { // MessageBox.Show("A lot link Exists for this job"); // } // ImportantDate iDate = db.ImportantDates.Find(strjobnumber); // if (iDate != null) // { // iDate.BaseID = strjobnumber; // iDate.RecvMaterial = dtReceiveMaterial; // iDate.StartFab = dtStartFab; // iDate.HeatTreat = dtHeatTreat; // iDate.StartMachining = dtStartMachining; // iDate.StartAssy = dtStartAssembly; // iDate.MachComp = dtMachineComplete; // iDate.RdyChk = dtReadyCheck; // iDate.RdySrc = dtReadySource; // iDate.DesRel = dtDataRelease; // db.SaveChanges(); // MessageBox.Show("Dates Updated. GREAT JOB!"); // } // else // { // ImportantDate iDate2 = new ImportantDate(); // iDate2.BaseID = strjobnumber; // iDate2.RecvMaterial = dtReceiveMaterial; // iDate2.StartFab = dtStartFab; // iDate2.HeatTreat = dtHeatTreat; // iDate2.StartMachining = dtStartMachining; // iDate2.StartAssy = dtStartAssembly; // iDate2.MachComp = dtMachineComplete; // iDate2.RdyChk = dtReadyCheck; // iDate2.RdySrc = dtReadySource; // iDate2.DesRel = dtDataRelease; // db.ImportantDates.Add(iDate2); // db.SaveChanges(); // MessageBox.Show("Dates Saved. GREAT JOB!"); // } }