public void saveImpactRating(CompleteRating impactRating, int VersID) { ImpactTypeRating saveRating = impactRating.ImpactRating; if (impactRating.ImpactRating.RatingID > 0) { ImpactTypeRating impact = db.ImpactTypeRatings.Find(impactRating.ImpactRating.RatingID); impact.Sscore = impactRating.ImpactRating.Sscore; impact.Pscore = impactRating.ImpactRating.Pscore; impact.Lscore = impactRating.ImpactRating.Lscore; } else if(saveRating.Sscore != null || saveRating.Pscore != null || saveRating.Lscore != null) { TaskRating rating = new TaskRating() { FacultyID = impactRating.FacultyID == 0 ? 2: impactRating.FacultyID, ReviewDate = DateTime.Now, VersID = VersID, }; ImpactTypeRating impact = new ImpactTypeRating() { Sscore = impactRating.ImpactRating.Sscore, Pscore = impactRating.ImpactRating.Pscore, Lscore = impactRating.ImpactRating.Lscore, TaskRating = rating }; db.TaskRatings.Add(rating); db.ImpactTypeRatings.Add(impact); } db.SaveChanges(); }
// POST api/<controller> public void Post(ImpactDTO value) { FacultyID = Int32.Parse(User.Identity.GetUserId()); TaskRating rating = new TaskRating() { FacultyID = FacultyID, ReviewDate = DateTime.Now, VersID = value.VersID, }; ImpactTypeRating impactRating = new ImpactTypeRating() { TaskRating = rating, Sscore = value.SScore, Pscore = value.PScore, Lscore = value.LScore, }; db.TaskRatings.Add(rating); db.ImpactTypeRatings.Add(impactRating); try { db.SaveChanges(); } catch { throw new HttpResponseException(HttpStatusCode.BadRequest); } }