public string ExportQuestion() { if (("OPTIONS").Equals(HttpContext.Request.HttpMethod)) { Response.StatusCode = 200; return(""); } var result = new ResultObject(); try { string _tempUploadFolder = ConfigurationManager.AppSettings["MediaTempUploadFolder"]; string _storeFolder = ConfigurationManager.AppSettings["ImagesStorePath"]; string fileName = "export_" + "" + DateTime.Now.ToString("yyyyMMddHHmmss"); string _tempStoreFolder = Server.MapPath(_tempUploadFolder + "/" + fileName); if (!Directory.Exists(_tempStoreFolder)) { Directory.CreateDirectory(_tempStoreFolder); } var question = service.GetAll().ToList(); result = Export(question, _storeFolder, _tempStoreFolder + "/"); ZipFile.CreateFromDirectory(_tempStoreFolder + "/", _tempStoreFolder + ".zip", CompressionLevel.Optimal, false); DeleteDirectory(_tempStoreFolder); result.Message = fileName + ".zip"; return(JsonConvert.SerializeObject(result)); } catch (Exception e) { result.Success = -1; result.Message = e.Message; return(JsonConvert.SerializeObject(result)); } }
public string Post([FromUri] string action, [FromBody] object value) { if ("AddMutiple".Equals(action)) { ResultObject resultt = new ResultObject(); try { var exam = JsonConvert.DeserializeObject <List <ExamQuestion> >(value.ToString()); var add = examQuestion.AddMutipleQuestion(exam); return(JsonConvert.SerializeObject(add)); } catch (Exception e) { resultt.Message = "EXCEPTION: " + e.Message + "Stack: " + e.StackTrace; return(JsonConvert.SerializeObject(resultt)); } } if ("DeleteMutiple".Equals(action)) { ResultObject resultt = new ResultObject(); try { var exam = JsonConvert.DeserializeObject <List <ExamQuestion> >(value.ToString()); var delete = examQuestion.DeleteMutiple(exam); return(JsonConvert.SerializeObject(delete)); } catch (Exception e) { resultt.Message = "EXCEPTION: " + e.Message + "Stack: " + e.StackTrace; return(JsonConvert.SerializeObject(resultt)); } } if ("random".Equals(action)) { ResultObject resultt = new ResultObject(); try { var exam = JsonConvert.DeserializeObject <ViewQuestionExam>(value.ToString()); var add = examQuestion.RandomQuestion(exam); return(JsonConvert.SerializeObject(add)); } catch (Exception e) { resultt.Message = "EXCEPTION: " + e.Message + "Stack: " + e.StackTrace; return(JsonConvert.SerializeObject(resultt)); } } var result = QuestionServices.GetAll().ToList(); return(JsonConvert.SerializeObject(result, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore })); }
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 GetAll() { ResultObject result = new ResultObject(); try { var list = service.GetAll().ToList(); result.Data = list; 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; result.Data = null; 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)); }