public ArchiveCode GetArchiveCodeByCode(string code) { if (code == null) { throw new IndexOutOfRangeException("No such code."); } ArchiveCode result = new ArchiveCode(); using (connection = new SqlConnection(connectionString)) { connection.Open(); string sql = "SELECT * FROM ArchiveCode WHERE Code = @code"; command = new SqlCommand(sql, connection); command.Parameters.AddWithValue("@code", code); using (reader = command.ExecuteReader()) { while (reader.Read()) { result.ID_ArchiveCode = reader.GetInt32("ID_ArchiveCode"); result.Code = reader.GetString("Code"); result.Name = reader.GetString("Name"); } } reader.Close(); command.Dispose(); connection.Close(); } return(result); }
public void UpdateArchiveCodeByCode(string c, ArchiveCode code) { if (c == null) { throw new IndexOutOfRangeException("No such code."); } if (code == null) { throw new IndexOutOfRangeException("No codes."); } using (connection = new SqlConnection(connectionString)) { connection.Open(); using (adapter = new SqlDataAdapter()) { string sql = "UPDATE ArchiveCode SET Code = @code, Name = @name WHERE Code = @c"; command = new SqlCommand(sql, connection); command.Parameters.AddWithValue("@code", code.Code); command.Parameters.AddWithValue("@name", code.Name); command.Parameters.AddWithValue("@c", c); adapter.UpdateCommand = command; adapter.UpdateCommand.ExecuteNonQuery(); } command.Dispose(); connection.Close(); } }
public List <ArchiveCode> GetArchiveCodes() { List <ArchiveCode> result = new List <ArchiveCode>(); using (connection = new SqlConnection(connectionString)) { connection.Open(); string sql = "SELECT * FROM ArchiveCode"; command = new SqlCommand(sql, connection); using (reader = command.ExecuteReader()) { while (reader.Read()) { ArchiveCode code = new ArchiveCode(reader.GetInt32("ID_ArchiveCode"), reader.GetString("Code"), reader.GetString("Name")); result.Add(code); } } reader.Close(); command.Dispose(); connection.Close(); } return(result); }
public void InsertArchiveCode(ArchiveCode code) { if (code.ID_ArchiveCode == 0) { throw new IndexOutOfRangeException("Empty code."); } code.ID_ArchiveCode = null; context.Add(code); context.SaveChanges(); }
public void DeleteArchiveCodeByCode() { //Arrange var archiveCodeEngine = new ArchiveCodeEngine(); const string Code = "7564"; //Act archiveCodeEngine.DeleteArchiveCodeByCode(Code); ArchiveCode code = archiveCodeEngine.GetArchiveCodeByCode(Code); //Assert Assert.Null(code.Code); Assert.Null(code.Name); }
public void GetArchiveCodeByCode() { //Arrange var archiveCodeEngine = new ArchiveCodeEngine(); const string Code = "01"; const string Name = "Основање, организација и развој"; //Act ArchiveCode code = archiveCodeEngine.GetArchiveCodeByCode(Code); //Assert Assert.Equal(1, code.ID_ArchiveCode); Assert.Equal(Name, code.Name); }
public void UpdateArchiveCodeByCode() { //Arrange var archiveCodeEngine = new ArchiveCodeEngine(); const string Code = "458"; const string Name = "updated"; //Act ArchiveCode code = new ArchiveCode(100, Code, Name); archiveCodeEngine.UpdateArchiveCodeByCode("456", code); code = archiveCodeEngine.GetArchiveCodeByCode(Code); //Assert Assert.Null(code); }
public void InsertArchiveCode() { //Arrange var archiveCodeEngine = new ArchiveCodeEngine(); const string Code = "09"; const string Name = "test9"; //Act ArchiveCode code = new ArchiveCode(100, Code, Name); archiveCodeEngine.InsertArchiveCode(code); code = archiveCodeEngine.GetArchiveCodeByCode(Code); //Assert Assert.Equal(Code, code.Code); Assert.Equal(Name, code.Name); }
public void DeleteArchiveCodeByCode(string code) { if (code == null) { throw new IndexOutOfRangeException("Invalid code."); } ArchiveCode c = context.ArchiveCodes.Where(c => c.Code == code).FirstOrDefault(); if (c == null) { //throw new ArgumentNullException("No code with that code in db."); return; } context.ArchiveCodes.Remove(c); context.SaveChanges(); }
public void DeleteArchiveCodeById(int id) { if (id == 0) { throw new IndexOutOfRangeException("Invalid id."); } ArchiveCode code = context.ArchiveCodes.Where(c => c.ID_ArchiveCode == id).FirstOrDefault(); if (code == null) { //throw new ArgumentNullException("No code with that id in db."); return; } context.ArchiveCodes.Remove(code); context.SaveChanges(); }
public void InsertArchiveCodes() { //Arrange var archiveCodeEngine = new ArchiveCodeEngine(); const string Code1 = "09"; const string Name1 = "test9"; const string Code2 = "0901"; const string Name2 = "test91"; const string Code3 = "0902"; const string Name3 = "test92"; List <ArchiveCode> archiveCodes = new List <ArchiveCode>(); List <ArchiveCode> result = new List <ArchiveCode>(); List <string> codes = new List <string>(); //Act ArchiveCode code1 = new ArchiveCode(100, Code1, Name1); ArchiveCode code2 = new ArchiveCode(101, Code2, Name2); ArchiveCode code3 = new ArchiveCode(102, Code3, Name3); archiveCodes.Add(code1); archiveCodes.Add(code2); archiveCodes.Add(code3); archiveCodeEngine.InsertArchiveCodes(archiveCodes); codes.Add(Code1); codes.Add(Code2); codes.Add(Code3); result = archiveCodeEngine.GetArchiveCodesByCodes(codes); //Assert foreach (ArchiveCode code in result) { Assert.Contains(code.Code, codes); } }
public void UpdateArchiveCodeByCode(string c, ArchiveCode code) { if (c == null) { throw new IndexOutOfRangeException("Invalid code."); } if (code == null) { throw new IndexOutOfRangeException("No codes."); } ArchiveCode oldCode = context.ArchiveCodes.Where(ac => ac.Code == c).FirstOrDefault(); if (oldCode == null) { //throw new ArgumentNullException("No code with that code in db."); return; } oldCode.Code = code.Code; oldCode.Name = code.Name; context.ArchiveCodes.Remove(oldCode); context.SaveChanges(); }
public void InsertArchiveCode(ArchiveCode code) { if (code.ID_ArchiveCode == 0) { throw new IndexOutOfRangeException("Empty code."); } using (connection = new SqlConnection(connectionString)) { connection.Open(); using (adapter = new SqlDataAdapter()) { string sql = "INSERT INTO ArchiveCode(Code, Name) VALUES(@code, @name)"; command = new SqlCommand(sql, connection); command.Parameters.AddWithValue("@code", code.Code); command.Parameters.AddWithValue("@name", code.Name); adapter.InsertCommand = command; adapter.InsertCommand.ExecuteNonQuery(); } command.Dispose(); connection.Close(); } }
/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { // credit: http://stackoverflow.com/a/263416/677735 unchecked // Overflow is fine, just wrap { int hash = 41; // Suitable nullity checks hash = hash * 59 + Id.GetHashCode(); if (OwnerEquipmentCodePrefix != null) { hash = hash * 59 + OwnerEquipmentCodePrefix.GetHashCode(); } if (OrganizationName != null) { hash = hash * 59 + OrganizationName.GetHashCode(); } hash = hash * 59 + MeetsResidency.GetHashCode(); if (LocalArea != null) { hash = hash * 59 + LocalArea.GetHashCode(); } if (Status != null) { hash = hash * 59 + Status.GetHashCode(); } if (DoingBusinessAs != null) { hash = hash * 59 + DoingBusinessAs.GetHashCode(); } if (RegisteredCompanyNumber != null) { hash = hash * 59 + RegisteredCompanyNumber.GetHashCode(); } if (PrimaryContact != null) { hash = hash * 59 + PrimaryContact.GetHashCode(); } if (IsMaintenanceContractor != null) { hash = hash * 59 + IsMaintenanceContractor.GetHashCode(); } if (WorkSafeBCPolicyNumber != null) { hash = hash * 59 + WorkSafeBCPolicyNumber.GetHashCode(); } if (WorkSafeBCExpiryDate != null) { hash = hash * 59 + WorkSafeBCExpiryDate.GetHashCode(); } if (CGLEndDate != null) { hash = hash * 59 + CGLEndDate.GetHashCode(); } if (ArchiveCode != null) { hash = hash * 59 + ArchiveCode.GetHashCode(); } if (ArchiveReason != null) { hash = hash * 59 + ArchiveReason.GetHashCode(); } if (ArchiveDate != null) { hash = hash * 59 + ArchiveDate.GetHashCode(); } if (Contacts != null) { hash = hash * 59 + Contacts.GetHashCode(); } if (Notes != null) { hash = hash * 59 + Notes.GetHashCode(); } if (Attachments != null) { hash = hash * 59 + Attachments.GetHashCode(); } if (History != null) { hash = hash * 59 + History.GetHashCode(); } if (EquipmentList != null) { hash = hash * 59 + EquipmentList.GetHashCode(); } return(hash); } }
/// <summary> /// Returns true if Owner instances are equal /// </summary> /// <param name="other">Instance of Owner to be compared</param> /// <returns>Boolean</returns> public bool Equals(Owner other) { if (other is null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( Id == other.Id || Id.Equals(other.Id) ) && ( OwnerEquipmentCodePrefix == other.OwnerEquipmentCodePrefix || OwnerEquipmentCodePrefix != null && OwnerEquipmentCodePrefix.Equals(other.OwnerEquipmentCodePrefix) ) && ( OrganizationName == other.OrganizationName || OrganizationName != null && OrganizationName.Equals(other.OrganizationName) ) && ( MeetsResidency == other.MeetsResidency || MeetsResidency.Equals(other.MeetsResidency) ) && ( LocalArea == other.LocalArea || LocalArea != null && LocalArea.Equals(other.LocalArea) ) && ( Status == other.Status || Status != null && Status.Equals(other.Status) ) && ( DoingBusinessAs == other.DoingBusinessAs || DoingBusinessAs != null && DoingBusinessAs.Equals(other.DoingBusinessAs) ) && ( RegisteredCompanyNumber == other.RegisteredCompanyNumber || RegisteredCompanyNumber != null && RegisteredCompanyNumber.Equals(other.RegisteredCompanyNumber) ) && ( PrimaryContact == other.PrimaryContact || PrimaryContact != null && PrimaryContact.Equals(other.PrimaryContact) ) && ( IsMaintenanceContractor == other.IsMaintenanceContractor || IsMaintenanceContractor != null && IsMaintenanceContractor.Equals(other.IsMaintenanceContractor) ) && ( WorkSafeBCPolicyNumber == other.WorkSafeBCPolicyNumber || WorkSafeBCPolicyNumber != null && WorkSafeBCPolicyNumber.Equals(other.WorkSafeBCPolicyNumber) ) && ( WorkSafeBCExpiryDate == other.WorkSafeBCExpiryDate || WorkSafeBCExpiryDate != null && WorkSafeBCExpiryDate.Equals(other.WorkSafeBCExpiryDate) ) && ( CGLEndDate == other.CGLEndDate || CGLEndDate != null && CGLEndDate.Equals(other.CGLEndDate) ) && ( ArchiveCode == other.ArchiveCode || ArchiveCode != null && ArchiveCode.Equals(other.ArchiveCode) ) && ( ArchiveReason == other.ArchiveReason || ArchiveReason != null && ArchiveReason.Equals(other.ArchiveReason) ) && ( ArchiveDate == other.ArchiveDate || ArchiveDate != null && ArchiveDate.Equals(other.ArchiveDate) ) && ( Contacts == other.Contacts || Contacts != null && Contacts.SequenceEqual(other.Contacts) ) && ( Notes == other.Notes || Notes != null && Notes.SequenceEqual(other.Notes) ) && ( Attachments == other.Attachments || Attachments != null && Attachments.SequenceEqual(other.Attachments) ) && ( History == other.History || History != null && History.SequenceEqual(other.History) ) && ( EquipmentList == other.EquipmentList || EquipmentList != null && EquipmentList.SequenceEqual(other.EquipmentList) )); }