Advertisement
svetlai

Update collection

Jan 31st, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.65 KB | None | 0 0
  1. public class RecruiterProfile
  2.     {
  3.         public RecruiterProfile()
  4.         {
  5.             this.JobOffers = new HashSet<JobOffer>();
  6.             this.Matches = new HashSet<Match>();
  7.             this.Messages = new HashSet<Message>();
  8.             this.DislikedJobSeekers = new HashSet<int>();
  9.             this.LikedJobSeekers = new HashSet<int>();
  10.         }
  11.  
  12.         [Key]
  13.         public int RecruiterProfileId { get; set; }
  14.  
  15.         public string UserId { get; set; }
  16.  
  17.         public virtual User User { get; set; }
  18.  
  19.         public virtual ICollection<JobOffer> JobOffers { get; set; }
  20.  
  21.         public virtual ICollection<Match> Matches { get; set; }
  22.  
  23.         public virtual ICollection<Message> Messages { get; set; }
  24.  
  25.         public ICollection<int> DislikedJobSeekers { get; set; }
  26.  
  27.         public ICollection<int> LikedJobSeekers { get; set; }
  28.     }
  29.  
  30. [HttpPut]
  31.         public IHttpActionResult Like(int id)
  32.         {
  33.             var recruiter = this.data.RecruiterProfiles.All()
  34.                 .FirstOrDefault(x => x.UserId == this.CurrentUserId);
  35.  
  36.             if (recruiter == null)
  37.             {
  38.                 return this.BadRequest("You must be a recruiter to do this.");
  39.             }
  40.  
  41.             if (recruiter.LikedJobSeekers.Contains(id))
  42.             {
  43.                 return this.BadRequest("You've already liked this guy.");
  44.             }
  45.  
  46.             if (recruiter.DislikedJobSeekers.Contains(id))
  47.             {
  48.                 recruiter.DislikedJobSeekers.Remove(id);
  49.             }
  50.  
  51.             recruiter.LikedJobSeekers.Add(id);
  52.             this.data.RecruiterProfiles.Update(recruiter);
  53.             this.data.SaveChanges();
  54.  
  55.             return this.Ok(recruiter);
  56.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement