public JsonResult LoadSurveys(SurveyListUserModel surveyList) { try { surveyList.SortColumnName = Request.Form["columns[" + Request.Form["order[0][column]"].FirstOrDefault() + "][name]"].FirstOrDefault(); surveyList.SortDirection = Request.Form["order[0][dir]"].FirstOrDefault(); //Get user code surveyList.EventCode = User.FindFirstValue(ClaimTypes.Name); surveyList.EventCode = surveyList.EventCode.Replace(Constants.SurveyUserName, ""); //Get list survey var data = _unitOfWork.SurveyRepository.LoadListSurveyUser(surveyList); //Put list survey to json result var result = Json(new { data = data.ListSurvey, draw = surveyList.Draw, recordsFiltered = data.TotalRowsAfterFiltering }); return(result); } catch (Exception e) { return(Json(new AjaxResponseModel(false, e.Message))); } }
/// <summary> /// This method to get list Survey from DB and put it into users/List Survey /// </summary> /// <param name="surveyListUser"></param> /// <returns></returns> public SurveyListUserModel LoadListSurveyUser(SurveyListUserModel surveyListUser) { try { var listSurveyReturn = new SurveyListUserModel(); var surveys = _context.Surveys.Where(x => !x.IsDeleted && x.Event.Code == surveyListUser.EventCode); listSurveyReturn.TotalRowsAfterFiltering = surveys.Count(); //Sort And Paging surveys = Filtering(surveys, surveyListUser); listSurveyReturn.ListSurvey = surveys .Select(s => new { s.Cd, s.InsertDate, s.MediaCd, MediaName = s.Media.Name, s.VisitTime, s.AgeRange, s.Gender, s.CareerCd, CareerName = s.Career.Name, s.IsMarried, s.LivingStatus, s.IsComeToBuy, s.IsVisitedReception, s.FavoriteArtist, SurveyArtistName = s.SurveyArtists.Select(a => new { a.Artist.Name, a.Artist.Code, }) }) .AsEnumerable() .Select(m => new SurveyItemUserModel() { Cd = m.Cd, InsertDate = m.InsertDate?.ToString(ExactDateTimeFormat), MediaName = m.MediaName, VisitTimeDescription = ((VisitTime)m.VisitTime).GetEnumDescription(), AgeRangeDescription = ((AgeRange)m.AgeRange).GetEnumDescription(), GenderName = ((GenderOfSurvey)Convert.ToInt32(m.Gender)).GetEnumDescription(), CareerName = m.CareerName, IsMarriedDescription = ((IsMarried)Convert.ToInt32(m.IsMarried)).GetEnumDescription(), LivingStatusDescription = ((LivingStatus)Convert.ToInt32(m.LivingStatus)).GetEnumDescription(), IsComeToBuyDescription = ((IsComeToBuy)Convert.ToInt32(m.IsComeToBuy)).GetEnumDescription(), FavoriteArtist = m.FavoriteArtist, SurveyArtistName = m.SurveyArtistName.OrderBy(m => m.Code).Select(y => y.Name).ToList(), }).ToList(); return(listSurveyReturn); } catch (Exception) { throw; } }