Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Linq;
- using System.Reflection;
- namespace ExercisesDAL
- {
- public class StudentModel
- {
- IRepository<Students> repository;
- public StudentModel()
- {
- repository = new SomeSchoolRepository<Students>();
- }
- public Students GetByLastName(string name)
- {
- List<Students> selectedStudent = null;
- try
- {
- selectedStudent = repository.GetByExpression(stu => stu.LastName == name);
- }
- catch (Exception ex)
- {
- Console.WriteLine("Problem in " + GetType().Name + " " +
- MethodBase.GetCurrentMethod().Name + " " + ex.Message);
- throw ex;
- }
- return selectedStudent.FirstOrDefault();
- }
- public Students GetById(int id)
- {
- List<Students> selectedStudent = null;
- try
- {
- selectedStudent = repository.GetByExpression(stu => stu.Id == id);
- }
- catch (Exception ex)
- {
- Console.WriteLine("Problem in " + GetType().Name + " " +
- MethodBase.GetCurrentMethod().Name + " " + ex.Message);
- throw ex;
- }
- return selectedStudent.FirstOrDefault();
- }
- public List<Students> GetAll()
- {
- List<Students> allStudents = new List<Students>();
- try
- {
- allStudents = repository.GetAll();
- }
- catch (Exception ex)
- {
- Console.WriteLine("Problem in " + GetType().Name + " " +
- MethodBase.GetCurrentMethod().Name + " " + ex.Message);
- throw ex;
- }
- return allStudents;
- }
- public int Add(Students newStudent)
- {
- try
- {
- repository.Add(newStudent);
- }
- catch(Exception ex)
- {
- Console.WriteLine("Problem in " + GetType().Name + " " +
- MethodBase.GetCurrentMethod().Name + " " + ex.Message);
- throw ex;
- }
- return newStudent.Id;
- }
- public UpdateStatus Update(Students updatedStudent)
- {
- UpdateStatus operationStatus = UpdateStatus.Failed;
- try
- {
- operationStatus = repository.Update(updatedStudent);
- }
- catch (Exception ex)
- {
- Console.WriteLine("Problem in " + GetType().Name + " " +
- MethodBase.GetCurrentMethod().Name + " " + ex.Message);
- throw ex;
- }
- return operationStatus;
- }
- public int Delete(int Id)
- {
- int studentsDeleted = -1;
- try
- {
- studentsDeleted = repository.Delete(Id);
- }
- catch (Exception ex)
- {
- Console.WriteLine("Problem in " + GetType().Name + " " +
- MethodBase.GetCurrentMethod().Name + " " + ex.Message);
- throw ex;
- }
- return studentsDeleted;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement