public string Getfilter([FromUri] string action, [FromBody] object value) { if (value != null) { if ("fillter".Equals(action)) { try { var filterObject = JsonConvert.DeserializeObject <QuestionFillterModel>(value.ToString()); return(JsonConvert.SerializeObject(QuestionServices.Filter(filterObject), Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore })); } catch (Exception ex) { return("Object fillter not convert valid"); } } } if ("AddMutiple".Equals(action)) { var exam = JsonConvert.DeserializeObject <List <ExamQuestion> >(value.ToString()); var add = examQuestion.AddMutipleQuestion(exam); return(JsonConvert.SerializeObject(add)); } if ("DeleteMutiple".Equals(action)) { var exam = JsonConvert.DeserializeObject <List <ExamQuestion> >(value.ToString()); var delete = examQuestion.DeleteMutiple(exam); return(JsonConvert.SerializeObject(delete)); } if ("random".Equals(action)) { var exam = JsonConvert.DeserializeObject <ViewQuestionExam>(value.ToString()); var add = examQuestion.RandomQuestion(exam); return(JsonConvert.SerializeObject(add)); } if ("getfillter".Equals(action)) { return(JsonConvert.SerializeObject(examQuestion.listFilters())); //return ""; } var result = QuestionServices.GetAll().ToList(); return(JsonConvert.SerializeObject(result, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore })); }
public string Post([FromUri] string action, [FromBody] object value) { ResultObject result = new ResultObject(); if (value == null) { result.Message = "Data null"; return(JsonConvert.SerializeObject(result)); } try { if ("search".Equals(action)) { var searchObj = JsonConvert.DeserializeObject <SearchPaging>(value.ToString()); result.Data = service.Search(searchObj); if (result.Data != null) { result.Success = 1; } return(JsonConvert.SerializeObject(result, Formatting.Indented, jsonSetting)); } if ("fillter".Equals(action)) { var filterObject = JsonConvert.DeserializeObject <QuestionFillterModel>(value.ToString()); result.Data = service.Filter(filterObject); if (result.Data != null) { result.Success = 1; } return(JsonConvert.SerializeObject(result, Formatting.Indented, jsonSetting)); } } catch (Exception e) { result.Message = "EXCEPTION: " + e.Message + "Stack: " + e.StackTrace; return(JsonConvert.SerializeObject(result)); } result.Message = "Action not allow"; return(JsonConvert.SerializeObject(result)); }
public string Post([FromUri] string action, [FromBody] object value) { var jsonSetting = new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }; ResultObject result = new ResultObject(); if (value == null && !"import".Equals(action.ToLower())) { result.Message = "Data null"; return(JsonConvert.SerializeObject(result)); } try { if ("search".Equals(action)) { var searchObj = JsonConvert.DeserializeObject <SearchPaging>(value.ToString()); result.Data = service.Search(searchObj); if (result.Data != null) { result.Success = 1; } return(JsonConvert.SerializeObject(result, Formatting.Indented, jsonSetting)); } if ("fillter".Equals(action)) { var filterObject = JsonConvert.DeserializeObject <QuestionFillterModel>(value.ToString()); result.Data = service.Filter(filterObject); if (result.Data != null) { result.Success = 1; } return(JsonConvert.SerializeObject(result, Formatting.Indented, jsonSetting)); } if ("export".Equals(action.ToLower())) { result.Message = Export(service.GetAll().ToList()); if (!"".Equals(result.Message)) { result.Success = 1; } return(JsonConvert.SerializeObject(result)); } if ("import".Equals(action.ToLower())) { string _tempUploadFolder = ConfigurationManager.AppSettings["MediaTempUploadFolder"]; string _storeFolder = ConfigurationManager.AppSettings["MediaUploadFolder"]; if (HttpContext.Current.Request.Files.Count < 1) { result.Message = "Not file upload"; return(JsonConvert.SerializeObject(result)); } HttpPostedFile file = HttpContext.Current.Request.Files[0]; if (file.ContentLength <= 0) { result.Message = "content file null"; return(JsonConvert.SerializeObject(result)); } else { result = importZip(file, _tempUploadFolder, _storeFolder); return(JsonConvert.SerializeObject(result)); } } } catch (Exception e) { result.Message = "EXCEPTION: " + e.Message + "Stack: " + e.StackTrace; return(JsonConvert.SerializeObject(result)); } result.Message = "Action not allow"; return(JsonConvert.SerializeObject(result)); }