Browse Source

job and parameter repository

confirmation-email
J 11 years ago
parent
commit
85ced0bce0
6 changed files with 197 additions and 3 deletions
  1. +1
    -0
      Sevomin.Models/Job.cs
  2. +29
    -2
      Sevomin.Models/JobParameter.cs
  3. +13
    -1
      Sevomin.Models/Repositories/IRepository.cs
  4. +85
    -0
      Sevomin.Models/Repositories/JobRepository.cs
  5. +67
    -0
      Sevomin.Models/Repositories/ParameterRepository.cs
  6. +2
    -0
      Sevomin.Models/UsersDbContext.cs

+ 1
- 0
Sevomin.Models/Job.cs View File

@ -33,5 +33,6 @@ namespace Sevomin.Models
public bool IsFullTime { get; set; }
public virtual ICollection<JobParameter> JobParameters { get; set; }
}
}

+ 29
- 2
Sevomin.Models/JobParameter.cs View File

@ -23,12 +23,39 @@ namespace Sevomin.Models
[Required]
public long JobId { get; set; }
public string StringValue { get; set; }
public decimal? NumericValue { get; set; }
public string StringValue { get; private set; }
public decimal? NumericValue { get; private set; }
public byte Moscow { get; set; }
public virtual Parameter Parameter { get; set; }
public virtual Job Job { get; set; }
public JobParameter()
{}
public JobParameter(Job job, Parameter parameter)
{
this.Job = job;
this.Parameter = parameter;
this.StringValue = "";
this.NumericValue = null;
this.Moscow = 0;
}
public void SetValue(string value)
{
decimal val;
if (decimal.TryParse(value, out val))
{
NumericValue = val;
StringValue = value;
}
else
{
NumericValue = null;
StringValue = value;
}
}
}
}

+ 13
- 1
Sevomin.Models/Repositories/IRepository.cs View File

@ -1,4 +1,5 @@
using System.Data.Entity.Core.Objects;
using System.Linq;
namespace Sevomin.Models.Repositories
{
@ -7,11 +8,22 @@ namespace Sevomin.Models.Repositories
void Add(T entity);
T Find(K identifier);
void Delete(T entity);
void Save(SaveOptions options = SaveOptions.AcceptAllChangesAfterSave);
void Save();
}
public interface IUserRepository : IRepository<string, User>
{
}
public interface IJobRepository : IRepository<long ,Job>
{
Job GetEmptyJobFor(Avalin avalin);
IQueryable<Job> ListAll();
}
public interface IParameterRepository : IRepository<long, Parameter>
{
IQueryable<Parameter> ListAll();
}
}

+ 85
- 0
Sevomin.Models/Repositories/JobRepository.cs View File

@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sevomin.Models.Repositories
{
public class JobRepository:IJobRepository
{
#region Singleton
private static JobRepository member;
private static object locker = new object();
private JobRepository()
{
}
static JobRepository()
{
lock (locker)
{
JobRepository.member = new JobRepository();
}
}
public static JobRepository Current
{
get
{
return JobRepository.member;
}
}
#endregion
#region JobRepository
public IQueryable<Job> ListAll()
{
return SevominDbContext.Current.Jobs;
}
public Job Find(long key)
{
return ListAll().SingleOrDefault(d => d.Id == key);
}
public void Delete(Job d)
{
SevominDbContext.Current.Jobs.Remove(d);
Save();
}
public void Add(Job d)
{
SevominDbContext.Current.Jobs.Add(d);
Save();
}
public void Save()
{
SevominDbContext.Current.SaveChanges();
}
public Job GetEmptyJobFor(Avalin avalin)
{
Job job = new Job();
foreach (var param in ParameterRepository.Current.ListAll())
{
JobParameter jp = new JobParameter(job, param);
job.JobParameters.Add(jp);
}
job.IsFullTime = true;
job.ShowCompanyLogo = false;
job.ShowCompanyName = false;
job.Avalin = avalin;
avalin.Jobs.Add(job);
return job;
}
#endregion
}
}

+ 67
- 0
Sevomin.Models/Repositories/ParameterRepository.cs View File

@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sevomin.Models.Repositories
{
public class ParameterRepository: IParameterRepository
{
#region Singleton
private static ParameterRepository member;
private static object locker = new object();
private ParameterRepository()
{
}
static ParameterRepository()
{
lock (locker)
{
ParameterRepository.member = new ParameterRepository();
}
}
public static ParameterRepository Current
{
get
{
return ParameterRepository.member;
}
}
#endregion
#region JobRepository
public IQueryable<Parameter> ListAll()
{
return SevominDbContext.Current.Parameters;
}
public Parameter Find(long key)
{
return ListAll().SingleOrDefault(d => d.Id == key);
}
public void Delete(Parameter d)
{
SevominDbContext.Current.Parameters.Remove(d);
Save();
}
public void Add(Parameter d)
{
SevominDbContext.Current.Parameters.Add(d);
Save();
}
public void Save()
{
SevominDbContext.Current.SaveChanges();
}
#endregion
}
}

+ 2
- 0
Sevomin.Models/UsersDbContext.cs View File

@ -43,5 +43,7 @@ namespace Sevomin.Models
public DbSet<Parameter> Parameters { get; set; }
public DbSet<ParameterValue> ParameterValues { get; set; }
public DbSet<Job> Jobs { get; set; }
}
}

Loading…
Cancel
Save