public int InsertServiceDate(Type814ServiceDate model) { using (var connection = new SqlConnection(connectionString)) using (var command = connection.CreateCommand("csp814ServiceDateInsert")) { SqlParameter keyParameter; command.AddWithValue("@Service_Key", model.ServiceKey) .AddIfNotEmptyOrDbNull("@Qualifier", model.Qualifier) .AddIfNotEmptyOrDbNull("@Date", model.Date) .AddIfNotEmptyOrDbNull("@Time", model.Time) .AddIfNotEmptyOrDbNull("@TimeCode", model.TimeCode) .AddIfNotEmptyOrDbNull("@PeriodFormat", model.PeriodFormat) .AddIfNotEmptyOrDbNull("@Period", model.Period) .AddIfNotEmptyOrDbNull("@NotesDate", model.NotesDate) .AddOutParameter("@Date_Key", SqlDbType.Int, out keyParameter); if (connection.State != ConnectionState.Open) { connection.Open(); } command.ExecuteNonQuery(); if (keyParameter.Value == null) { throw new Exception(); } var dateKey = (int)keyParameter.Value; model.DateKey = dateKey; return(dateKey); } }
public void When_Saving_Header_With_Any_Service_Dates_Then_Insert_Service_Date_Is_Called() { // arrange const int serviceKey = 2; var date = new Type814ServiceDate { Date = "mock" }; var service = new Type814Service(); service.AddDate(date); var header = new Type814Header(); header.AddService(service); dataAccess.Stub(x => x.InsertHeader(Arg.Is(header))) .Return(1); dataAccess.Stub(x => x.InsertService(Arg.Is(service))) .Return(serviceKey); dataAccess.Expect(x => x.InsertServiceDate(Arg.Is(date))) .Return(1); // act concern.SaveHeader(header); // assert Assert.AreEqual(serviceKey, date.ServiceKey); dataAccess.VerifyAllExpectations(); }
public Type814ServiceDate ParseServiceDate(XElement element, IDictionary <string, XNamespace> namespaces) { XNamespace empty; if (!namespaces.TryGetValue(string.Empty, out empty)) { empty = XNamespace.None; } var model = new Type814ServiceDate { Qualifier = element.GetChildText(empty + "Qualifier"), Date = element.GetChildText(empty + "Date"), Time = element.GetChildText(empty + "Time"), TimeCode = element.GetChildText(empty + "TimeCode"), PeriodFormat = element.GetChildText(empty + "PeriodFormat"), Period = element.GetChildText(empty + "Period"), NotesDate = element.GetChildText(empty + "NotesDate"), }; return(model); }
public Type814ServiceDate[] ListServiceDates(int serviceKey) { using (var connection = new SqlConnection(connectionString)) using (var command = connection.CreateCommand("esp_814ServiceDateList")) { command.AddWithValue("@Service_Key", serviceKey); if (connection.State != ConnectionState.Open) { connection.Open(); } var collection = new List <Type814ServiceDate>(); using (var reader = command.ExecuteReader()) { while (reader.Read()) { var item = new Type814ServiceDate { DateKey = reader.GetInt32("Date_Key"), ServiceKey = serviceKey, }; reader.TryGetString("Qualifier", x => item.Qualifier = x); reader.TryGetString("Date", x => item.Date = x); reader.TryGetString("Time", x => item.Time = x); reader.TryGetString("TimeCode", x => item.TimeCode = x); reader.TryGetString("PeriodFormat", x => item.PeriodFormat = x); reader.TryGetString("Period", x => item.Period = x); reader.TryGetString("NotesDate", x => item.NotesDate = x); collection.Add(item); } return(collection.ToArray()); } } }
public int InsertServiceDate(Type814ServiceDate model) { return(-1); }