public static long SendTestimonial(TestimonialDTO testimonial) { try { using (var ctx = new DAL.tutorDBEntities()) { var dbTestimonial = ctx.Testimonials.FirstOrDefault(x => x.id == testimonial.id) ?? ctx.Testimonials.Add(new DAL.Testimonials()); dbTestimonial.requestId = testimonial.requestId; dbTestimonial.text = testimonial.text; dbTestimonial.date = testimonial.date; dbTestimonial.star = testimonial.star; ctx.SaveChanges(); return(dbTestimonial.id); } } catch (Exception ex) { throw; //return -1; } }
public static TestimonialDTO GetTestimonial(long requestId) { try { using (var ctx = new DAL.tutorDBEntities()) { var dbTestimonial = ctx.Testimonials.FirstOrDefault(x => x.requestId == requestId); if (dbTestimonial != null) { var testimonial = new TestimonialDTO { text = dbTestimonial.text, star = dbTestimonial.star, date = dbTestimonial.date }; return(testimonial); } return(null); } } catch (Exception ex) { return(null); } }