public IActionResult PutARating(long id_Doctor, [FromBody] RatingViewModel model) { if (model == null) { return(BadRequest()); } var doc = db.Doctor.FirstOrDefault(d => d.Id == id_Doctor); if (doc == null) { return(BadRequest()); } doc.TotalSumRating = model.TotalSumRating; doc.NumRated = model.NumRated; doc.Rating = model.Rating; db.Update(doc); db.SaveChanges(); Appreciated ap = (Appreciated)model; ap.Fk_Doctor = id_Doctor; db.Add(ap); db.SaveChanges(); return(Ok(new { doctor = doc, appreciated = ap })); }
public IActionResult ChangeRating(long id_Doctor, [FromBody] RatingViewModel model) { if (model == null) { return(BadRequest()); } var doc = db.Doctor.FirstOrDefault(d => d.Id == id_Doctor); if (doc == null) { return(BadRequest()); } doc.TotalSumRating = model.TotalSumRating; doc.NumRated = model.NumRated; doc.Rating = model.Rating; db.Update(doc); db.SaveChanges(); Appreciated ap = db.Appreciated.FirstOrDefault(a => a.Id == model.Id_Appreciated); ap.Fk_Doctor = id_Doctor; ap.Fk_User = model.Id_User; ap.Assessment = model.Assessment; ap.dateTime = DateTime.Now; db.Update(ap); db.SaveChanges(); return(Ok(new { doctor = doc, appreciated = ap })); }