// Gets All Feedback internal List <FeedbackEntity> GetAllFeedback(int SortOrder, int PageNumber, int PageSize, out int TotalRecords, string HostName, string FeedbackType) { List <FeedbackEntity> results = new List <FeedbackEntity>(); try { TotalRecords = 0; StoredProcedureEntity sproc = new StoredProcedureEntity(); sproc.StoredProcedureName = "mapp.GetAllFeedback"; // MP-846 Admin database cleanup and code cleanup. sproc.StoredProceduresParameter.Add(GetParam("@SortOrder", SortOrder.ToString(), SQLServerDatatype.IntDataType)); sproc.StoredProceduresParameter.Add(GetParam("@PageNumber", PageNumber.ToString(), SQLServerDatatype.IntDataType)); sproc.StoredProceduresParameter.Add(GetParam("@PageSize", PageSize.ToString(), SQLServerDatatype.IntDataType)); sproc.StoredProceduresParameter.Add(GetParam("@TotalRecords", TotalRecords.ToString(), SQLServerDatatype.IntDataType, ParameterDirection.Output)); sproc.StoredProceduresParameter.Add(GetParam("@Host", string.IsNullOrEmpty(HostName) ? null : HostName.ToString(), SQLServerDatatype.VarcharDataType)); sproc.StoredProceduresParameter.Add(GetParam("@FeedbackType", string.IsNullOrEmpty(FeedbackType) ? null : FeedbackType.ToString(), SQLServerDatatype.VarcharDataType)); string outParam = ""; DataTable dt; dt = sql.ExecuteDataTableWithOutputParam(CommandType.StoredProcedure, sproc, out outParam); if (dt != null && dt.Rows.Count > 0) { results = new FeedbackAdapter().Adapt(dt); TotalRecords = Convert.ToInt32(outParam); } } catch (Exception) { throw; } return(results); }
public List <FeedbackDto> GetAll() { List <FeedbackDto> myFeedbacks = new List <FeedbackDto>(); _dbContext.Feedbacks.ToList().ForEach(feedback => myFeedbacks.Add(FeedbackAdapter.FeedbackToFeedbackDto(feedback))); return(myFeedbacks); }
public void RemovePreviousFeedback(FeedbackDto feedbackDto, Patient patient) { if (patient.Feedback != null) { _dbContext.Remove(patient.Feedback); } patient.Feedback = FeedbackAdapter.FeedbackDtoToFeedback(feedbackDto); }
public List <FeedbackDto> GetVisibleFeedbacks() { List <FeedbackDto> myFeedbacks = new List <FeedbackDto>(); List <Feedback> visibleFeedbacks = _dbContext.Feedbacks.Where(feedback => feedback.IsVisible == true).ToList(); visibleFeedbacks.ForEach(feedback => myFeedbacks.Add(FeedbackAdapter.FeedbackToFeedbackDto(feedback))); return(myFeedbacks); }
public FeedbackDto GetById(int feedbackId) { Feedback myFeedback = _dbContext.Feedbacks.SingleOrDefault(feedback => feedback.Id == feedbackId); if (myFeedback == null) { return(null); } return(FeedbackAdapter.FeedbackToFeedbackDto(myFeedback)); }
/// <summary> This method converts <paramref name="dto"/> to <c>Feedback</c> using <c>FeedbackAdapter</c> and sends it to <c>FeedbackRepository</c>. </summary> /// <param name="dto"><c>dto</c> is Data Transfer Object of a <c>Feedback</c> that contains <c>Message</c>, <c>IsPublic</c>, <c>IsAnonymous</c> and <c>PatientId</c>. /// </param> /// <returns>if patient exists returns successfully created feedback; otherwise, return <c>null</c></returns> public Feedback Create(FeedbackDto dto) { PatientUser patient = FeedbackRepository.FindPatient(); if (patient == null) { return(null); } Feedback feedback = FeedbackAdapter.FeedbackDtoToFeedback(dto, patient); return(FeedbackRepository.Add(feedback)); }
public FeedbackDto ShowFeedback(int feedbackId) { Feedback myFeedback = FeedbackAdapter.FeedbackDtoToFeedback(GetById(feedbackId)); Patient myPatient = _dbContext.Patients.SingleOrDefault(patient => patient.Id == myFeedback.PatientId); if (myFeedback == null) { return(null); } myFeedback.IsVisible = true; myPatient.Feedback.IsVisible = true; _dbContext.SaveChanges(); return(FeedbackAdapter.FeedbackToFeedbackDto(myFeedback)); }
public FeedbackDto Add(FeedbackDto feedbackDto) { if (feedbackDto == null) { return(null); } Patient myPatient = _dbContext.Patients.SingleOrDefault(patient => patient.Id == feedbackDto.PatientId); RemovePreviousFeedback(feedbackDto, myPatient); _dbContext.Feedbacks.Add(FeedbackAdapter.FeedbackDtoToFeedback(feedbackDto)); _dbContext.SaveChanges(); return(feedbackDto); }
public void GetAdminCommentsTest() { //Arrange var baseHttpResponse = new BaseHttpResponse { HttpStatusCode = HttpStatusCode.OK, Description = "[{id:1,'userid':'sample'}]" }; Mock <HttpRequest> request = new Mock <HttpRequest>(); request.Setup(x => x.Headers).Returns(new HeaderDictionary()); _mockHttpContext.Setup(x => x.Request).Returns(request.Object); Mock <IAuthenticationService> auth = new Mock <IAuthenticationService>(); Mock <IServiceProvider> service = new Mock <IServiceProvider>(); service.Setup(x => x.GetService(It.IsAny <Type>()) ).Returns(auth.Object ); _mockHttpContext.Setup(x => x.RequestServices).Returns( service.Object); _mokhttpContextAccessor.Setup(_ => _.HttpContext).Returns( _mockHttpContext.Object ); var settings = new ServiceSettings { UserServiceUrl = "http://localhost:8080/feedback/" }; var serviceResponse = (HttpWebRequest)WebRequest.Create(new Uri(settings.UserServiceUrl + "getAdminComments")); _mokconfig.Setup(s => s.Value).Returns(settings); _mokserviceHelper.Setup(s => s.CreateWebRequest(It.IsAny <ServiceRequest>())).Returns(serviceResponse); _mokserviceHelper.Setup(s => s.HandleRequest(serviceResponse)).Returns(baseHttpResponse); //Act _feedbackAdapter = new FeedbackAdapter(_mokserviceHelper.Object, _mokconfig.Object, _moklog.Object, _mokhttpContextAccessor.Object); var actual = _feedbackAdapter.GetAdminComments("sample"); //Assert Assert.AreEqual("sample", actual[0].userid); }
public void SaveFeedbackQuestionTest() { //Arrange var feedBack = new Feedback(); var baseHttpResponse = new BaseHttpResponse { HttpStatusCode = HttpStatusCode.OK }; Mock <HttpRequest> request = new Mock <HttpRequest>(); request.Setup(x => x.Headers).Returns(new HeaderDictionary()); _mockHttpContext.Setup(x => x.Request).Returns(request.Object); Mock <IAuthenticationService> auth = new Mock <IAuthenticationService>(); Mock <IServiceProvider> service = new Mock <IServiceProvider>(); service.Setup(x => x.GetService(It.IsAny <Type>()) ).Returns(auth.Object ); _mockHttpContext.Setup(x => x.RequestServices).Returns( service.Object); _mokhttpContextAccessor.Setup(_ => _.HttpContext).Returns( _mockHttpContext.Object ); var settings = new ServiceSettings { FeedbackServiceUrl = "http://localhost:8080/Feedback/" }; var serviceResponse = (HttpWebRequest)WebRequest.Create(new Uri(settings.FeedbackServiceUrl + "saveFeedbackQuestion")); _mokconfig.Setup(s => s.Value).Returns(settings); _mokserviceHelper.Setup(s => s.CreateWebRequest(It.IsAny <ServiceRequest>())).Returns(serviceResponse); _mokserviceHelper.Setup(s => s.HandleRequest(serviceResponse)).Returns(baseHttpResponse); //Act _feedbackAdapter = new FeedbackAdapter(_mokserviceHelper.Object, _mokconfig.Object, _moklog.Object, _mokhttpContextAccessor.Object); _feedbackAdapter.SaveFeedbackQuestion(feedBack); //Assert _mokserviceHelper.Verify(s => s.CreateWebRequest(It.IsAny <ServiceRequest>())); _mokserviceHelper.Verify(s => s.HandleRequest(serviceResponse)); }