public void UpdateForeignStudent(ForeignStudent foreignStudent, ref List <string> errors) { var conn = new SqlConnection(ConnectionString); try { var adapter = new SqlDataAdapter(UpdateForeignStudentInfoProcedure, conn) { SelectCommand = { CommandType = CommandType.StoredProcedure } }; adapter.SelectCommand.Parameters.Add(new SqlParameter("@sid", SqlDbType.VarChar, 20)); adapter.SelectCommand.Parameters.Add(new SqlParameter("@under_gpa", SqlDbType.Float)); adapter.SelectCommand.Parameters.Add(new SqlParameter("@toefl", SqlDbType.Float)); adapter.SelectCommand.Parameters["@sid"].Value = foreignStudent.Sid; adapter.SelectCommand.Parameters["@under_gpa"].Value = foreignStudent.Under_gpa; adapter.SelectCommand.Parameters["@toefl"].Value = foreignStudent.Toefl; var dataSet = new DataSet(); adapter.Fill(dataSet); } catch (Exception e) { errors.Add("Error: " + e); } finally { conn.Dispose(); } }
public string InsertForeignStudent(ForeignStudent foreignStudent) { var errors = new List <string>(); var repository = new ForeignStudentRepository(); var service = new ForeignStudentService(repository); service.InsertForeignStudent(foreignStudent, ref errors); if (errors.Count == 0) { return("ok"); } return("error"); }
public void InsertForeignStudentErrorTest2() { //// Arranage var errors = new List <string>(); var mockRepository = new Mock <IForeignStudentRepository>(); var foreignStudentService = new ForeignStudentService(mockRepository.Object); var foreignStudent = new ForeignStudent { Sid = string.Empty }; //// Act foreignStudentService.InsertForeignStudent(foreignStudent, ref errors); //// Assert Assert.AreEqual(1, errors.Count); }
public void InsertForeignStudent(ForeignStudent foreignStudent, ref List <string> errors) { if (foreignStudent == null) { errors.Add("ForeignStudent cannot be null"); throw new ArgumentException(); } if (foreignStudent.Sid.Length < 5) { errors.Add("Invalid foreignStudent ID"); throw new ArgumentException(); } this.repository.InsertForeignStudent(foreignStudent, ref errors); }
public List <ForeignStudent> GetForeignStudentList(ref List <string> errors) { var conn = new SqlConnection(ConnectionString); var foreignStudentList = new List <ForeignStudent>(); try { var adapter = new SqlDataAdapter(GetForeignStudentListProcedure, conn) { SelectCommand = { CommandType = CommandType.StoredProcedure } }; var dataSet = new DataSet(); adapter.Fill(dataSet); if (dataSet.Tables[0].Rows.Count == 0) { return(null); } for (var i = 0; i < dataSet.Tables[0].Rows.Count; i++) { var foreignStudent = new ForeignStudent { Sid = dataSet.Tables[0].Rows[i]["sid"].ToString(), Under_gpa = (float)Convert.ToDouble(dataSet.Tables[0].Rows[i]["under_gpa"].ToString()), Toefl = (float)Convert.ToDouble(dataSet.Tables[0].Rows[i]["toefl"].ToString()) }; foreignStudentList.Add(foreignStudent); } } catch (Exception e) { errors.Add("Error: " + e); } finally { conn.Dispose(); } return(foreignStudentList); }
public ForeignStudent GetForeignStudentDetail(string id, ref List <string> errors) { var conn = new SqlConnection(ConnectionString); ForeignStudent foreignStudent = null; try { var adapter = new SqlDataAdapter(GetForeignStudentInfoProcedure, conn) { SelectCommand = { CommandType = CommandType.StoredProcedure } }; adapter.SelectCommand.Parameters.Add(new SqlParameter("@sid", SqlDbType.VarChar, 20)); adapter.SelectCommand.Parameters["@sid"].Value = id; var dataSet = new DataSet(); adapter.Fill(dataSet); if (dataSet.Tables[0].Rows.Count == 0) { return(null); } foreignStudent = new ForeignStudent { Sid = dataSet.Tables[0].Rows[0]["sid"].ToString(), Under_gpa = (float)Convert.ToDouble(dataSet.Tables[0].Rows[0]["under_gpa"].ToString()), Toefl = (float)Convert.ToDouble(dataSet.Tables[0].Rows[0]["toefl"].ToString()) }; } catch (Exception e) { errors.Add("Error: " + e); } finally { conn.Dispose(); } return(foreignStudent); }
public void UpdateForeignStudent(ForeignStudent foreignStudent, ref List <string> errors) { if (foreignStudent == null) { errors.Add("ForeignStudent cannot be null"); throw new ArgumentException(); } if (string.IsNullOrEmpty(foreignStudent.Sid)) { errors.Add("Invalid student id"); throw new ArgumentException(); } if (foreignStudent.Sid.Length < 5) { errors.Add("Invalid student id"); throw new ArgumentException(); } this.repository.UpdateForeignStudent(foreignStudent, ref errors); }
static void Main(string[] args) { Console.WriteLine("---Klasa abstrakcyjna i polimorfizm---\n"); Student s1 = new DomesticStudent("Jacek", "Kowalczyk", "Poland", "s1345", 15, 0); Student s2 = new ForeignStudent("Robert", "Muller", "Germany", "s1077"); Console.WriteLine(s1.CalculateYearlyTuitionFee()); Console.WriteLine(s2.CalculateYearlyTuitionFee()); Console.WriteLine("\n---Dziedziczenie overlapping---\n"); EventParticipant t1 = new EventParticipant("Tomasz", "Kowalski", "Poland", new DateTime(2000, 11, 30), new List <ParticipationType> { ParticipationType.Player }, null, "21"); EventParticipant t2 = new EventParticipant("Grzegorz", "Lewandowski", "Poland", new DateTime(1976, 01, 06), new List <ParticipationType> { ParticipationType.Referee }, "S982EV", null); EventParticipant t3 = new EventParticipant("Paweł", "Nowak", "Poland", new DateTime(1988, 06, 14), new List <ParticipationType> { ParticipationType.Player, ParticipationType.Referee }, "A317B", "33"); Console.WriteLine(t1.isPlayer()); Console.WriteLine(t1.isReferee()); Console.WriteLine(t1.ToString()); Console.WriteLine(t2.isPlayer()); Console.WriteLine(t2.isReferee()); Console.WriteLine(t2.ToString()); Console.WriteLine(t3.isPlayer()); Console.WriteLine(t3.isReferee()); Console.WriteLine(t3.ToString()); Console.WriteLine("\n---Dziedziczenie dynamiczne---\n"); Account acc1 = new AccountPremium("Thomas", new DateTime(2020, 05, 11), "England", new MailAddress("*****@*****.**"), new DateTime(2020, 05, 20), SubscriptionType.Silver); Account acc2 = new AccountNormal("Janeq", new DateTime(2018, 09, 29), "Poland", new MailAddress("*****@*****.**")); Console.WriteLine(acc1.ToString()); Console.WriteLine(acc2.ToString()); acc1 = new AccountNormal(acc1); acc2 = new AccountPremium(acc2, new DateTime(2019, 10, 24), SubscriptionType.Diamond); Console.WriteLine(acc1.ToString()); Console.WriteLine(acc2.ToString()); acc1 = new AccountPremium(acc1, new DateTime(2020, 05, 20), SubscriptionType.Silver); Console.WriteLine(acc1.ToString()); Console.WriteLine("\n---Wielodziedziczenie---\n"); Car c1 = new CombustionCar("Lamborghini Huracan", 610, 2016, 11.0, 83); Car c2 = new ElectricCar("BMW i3", 170, 2013, 260.0, 13.1); Car c3 = new HybridCar("Toyota C-HR", 122, 2017, 3.6, 43, 50.0, 2.0); Console.WriteLine(c1.CalculateNeededUnit(250.00)); Console.WriteLine(c2.CalculateNeededUnit(250.00)); Console.WriteLine(c3.CalculateNeededUnit(250.00) + "\n"); Console.WriteLine(c3.ToString()); Console.WriteLine("\n---Wieloaspektowe---\n"); Device d1 = new Device("JBL", "Flip 5", "Blue", 12); Device d2 = new Device("Steelseries", "Arctis 5", "Black", 3.0); Mouse m1 = new Mouse("Logitech", "G PRO", "Black", 7, 25600); Keyboard k1 = new Keyboard("Razer", "Huntsman", "Black", SwitchType.Mechanical, true); Console.WriteLine(d1.GetConnection()); Console.WriteLine(d2.GetConnection() + "\n"); Console.WriteLine(d1.ToString()); Console.WriteLine(d2.ToString()); Console.WriteLine(m1.ToString()); Console.WriteLine(k1.ToString()); }
static void Main(string[] args) { Console.WriteLine("Hello SDA6! :-)"); SecondProject sp = new SecondProject(); Console.WriteLine(sp.Method1()); int variable01 = 100; const int variable02 = 50; Console.WriteLine(variable01 > variable02); int x = 10; Console.WriteLine(x); Console.WriteLine(x++); Console.WriteLine(++x); if (x == 12) { x++; Console.WriteLine(x); } while (x < 20) { Console.Write(x + " "); x++; } Console.WriteLine(); do { Console.Write(x + " "); x++; } while (x < 40); Console.WriteLine(); for (x = 1; x < 20; x++) { Console.Write(x + " "); } Console.WriteLine(); // StringBuilder StringBuilder sb = new StringBuilder("Hello"); sb.Insert(5, " Andrzej!"); Console.WriteLine(sb); Course course = new Course(); course.CourseName = "Java Programming"; Console.WriteLine("Course name " + course.CourseName); Student s = new Student(); s.PersonID = "123"; s.Name = "Alex"; s.Print(); ForeignStudent fs = new ForeignStudent(); fs.PersonID = "9873"; fs.Name = "Igor"; fs.HomeUni = "Moscow"; fs.Print(); Console.Read(); }