You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.1 KiB

11 years ago
11 years ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace Sevomin.Models.Repositories
  7. {
  8. public class JobRepository:IJobRepository
  9. {
  10. #region Singleton
  11. private static JobRepository member;
  12. private static object locker = new object();
  13. private JobRepository()
  14. {
  15. }
  16. static JobRepository()
  17. {
  18. lock (locker)
  19. {
  20. JobRepository.member = new JobRepository();
  21. }
  22. }
  23. public static JobRepository Current
  24. {
  25. get
  26. {
  27. return JobRepository.member;
  28. }
  29. }
  30. #endregion
  31. #region JobRepository
  32. public IQueryable<Job> ListAll()
  33. {
  34. return SevominDbContext.Current.Jobs;
  35. }
  36. public Job Find(long key)
  37. {
  38. return ListAll().SingleOrDefault(d => d.Id == key);
  39. }
  40. public void Delete(Job d)
  41. {
  42. SevominDbContext.Current.Jobs.Remove(d);
  43. Save();
  44. }
  45. public void Add(Job d)
  46. {
  47. SevominDbContext.Current.Jobs.Add(d);
  48. Save();
  49. }
  50. public void Save()
  51. {
  52. SevominDbContext.Current.SaveChanges();
  53. }
  54. public Job GetEmptyJobFor(Avalin avalin)
  55. {
  56. Job job = new Job();
  57. var parameters = ParameterRepository.Current.ListAll();
  58. job.JobParameters = new List<JobParameter>();
  59. foreach (var param in ParameterRepository.Current.ListAll())
  60. {
  61. JobParameter jp = new JobParameter(job, param);
  62. job.JobParameters.Add(jp);
  63. }
  64. job.IsFullTime = true;
  65. job.ShowCompanyLogo = false;
  66. job.ShowCompanyName = false;
  67. job.CreateDate = DateTime.UtcNow;
  68. job.Avalin = avalin;
  69. avalin.Jobs.Add(job);
  70. return job;
  71. }
  72. #endregion
  73. }
  74. }