// PUT: api/AppointmentFeedback/5 public IHttpActionResult Put(long?id, [FromBody] AppointmentFeedbackViewModel model) { try { if (!id.HasValue) { return(Ok(new { status = false, data = "Please provide a valid ID." })); } else { if (model != null) { var appointmentFeedback = _db.tblAppointmentFeedbacks.Find(id); if (appointmentFeedback != null) { appointmentFeedback.BusinessCustomerId = model.BusinessCustomerId; appointmentFeedback.BusinessEmployeeId = model.BusinessEmployeeId; appointmentFeedback.Created = (model.Created.HasValue) ? model.Created.Value.ToUniversalTime() : model.Created; appointmentFeedback.Feedback = model.Feedback; appointmentFeedback.IsActive = model.IsActive; appointmentFeedback.IsEmployee = model.IsEmployee; appointmentFeedback.Rating = model.Rating; appointmentFeedback.AppointmentId = model.AppointmentId; _db.Entry(appointmentFeedback).State = EntityState.Modified; var response = _db.SaveChanges(); if (response > 0) { return(Ok(new { status = true, data = appointmentFeedback })); } else { return(Ok(new { status = false, data = "There was a problem to update the data." })); } } } return(Ok(new { status = false, data = "Not a valid data to update. Please provide a valid id." })); } } catch (Exception ex) { return(BadRequest(ex.Message.ToString())); } }
// POST: api/AppointmentFeedback public IHttpActionResult Post([FromBody] AppointmentFeedbackViewModel model) { try { if (model != null) { var appointmentFeedback = new tblAppointmentFeedback() { BusinessCustomerId = model.BusinessCustomerId, BusinessEmployeeId = model.BusinessEmployeeId, Created = (model.Created.HasValue) ? model.Created.Value.ToUniversalTime() : model.Created, Feedback = model.Feedback, IsActive = model.IsActive, IsEmployee = model.IsEmployee, Rating = model.Rating, AppointmentId = model.AppointmentId }; _db.tblAppointmentFeedbacks.Add(appointmentFeedback); var response = _db.SaveChanges(); if (response > 0) { return(Ok(new { status = true, data = appointmentFeedback })); } else { return(Ok(new { status = false, data = "There was a problem." })); } } else { return(Ok(new { status = false, data = "There was a problem." })); } } catch (Exception ex) { return(BadRequest(ex.Message.ToString())); } }