public bool InsertRating(DanhGia model) { try { db.DanhGias.Add(model); db.SaveChanges(); UpdateRatingProduct(model.MaSP); } catch (Exception) { return false; } return true; }
public bool UpdateRating(DanhGia model) { DanhGia dg = db.DanhGias.Find(model.MaSP, model.NguoiDung); if (dg == null) { return InsertRating(model); } try { dg.Diem = model.Diem; db.Entry(dg).State = EntityState.Modified; db.SaveChanges(); UpdateRatingProduct(model.MaSP); } catch (Exception) { return false; } return true; }