/// <summary> /// Paging işlemi yapıldığında veya sorting yapıldığında kullanılacak /// </summary> /// <param name="pageCount"></param> /// <param name="showDataCount"></param> /// <param name="sortName"></param> /// <param name="returnOutput"></param> /// <returns></returns> public List <T> GetData(int pageCount, int showDataCount, string sortName, ref ReturnOutput returnOutput) { var retVal = JsonRepositoryService <T> .GetReadAllJsonData(typeEntity.Name, pageCount, showDataCount, sortName, ref returnOutput); string inputs = "pageCount = " + pageCount.ToString() + " showDataCount = " + showDataCount + " sortName " + sortName; LogHelper.WriteLog("BasePageActionModel", "GetData : " + typeEntity.Name + Environment.NewLine + " Inputs : " + inputs + Environment.NewLine + "ErrorCode = " + returnOutput.ErrorCode + " ErrorMessage = " + returnOutput.ErrorMessage); return(retVal); }
/// <summary> /// /// </summary> /// Image eklerken alt klasör yolu gerekli /// <param name="returnOutput"></param> /// <returns></returns> public List <T> GetDataWithPath(string filePath, ref ReturnOutput returnOutput) { var result = JsonRepositoryService <T> .GetReadAllJsonData(filePath, ref returnOutput); //Type t = entity.GetType(); LogHelper.WriteLog("BasePageActionModel", "GetData : " + typeEntity.Name + Environment.NewLine + " ErrorCode = " + returnOutput.ErrorCode + " ErrorMessage = " + returnOutput.ErrorMessage); return(result); }
public static void GetReadAllJsonData() { BasePageActionModel <Content> baseAction = new BasePageActionModel <Content>(_dataPath, _logPath); ReturnOutput returnOutput = new ReturnOutput(); var result = baseAction.GetData(ref returnOutput); //var result = baseAction.GetData(1,2,"",ref returnOutput); Console.WriteLine(result.Count); }
public static void ReadJsonAsObjetListAllData() { ReturnOutput returnOutput = new ReturnOutput(); _dataPath = @"D:\JsonData\Dernek\Town\"; BasePageActionModel <Content> baseAction = new BasePageActionModel <Content>(_dataPath, _logPath); var result = baseAction.ReadJsonAsObjectListAllData("Town_Turkey.json", ref returnOutput); //List<CountryModel> data = JsonRepositoryService<CountryModel>.ReadJsonAsObjectListAllData("Town_Turkey.json",ref returnOutput); }
public static void DeleteData() { ContentCategory contentCategory = new ContentCategory(); BasePageActionModel <ContentCategory> baseAction = new BasePageActionModel <ContentCategory>(_dataPath, _logPath); ReturnOutput returnOutput = new ReturnOutput(); var result = baseAction.DeleteData("", ""); Console.WriteLine(result); }
public static T UpdateJsonData(T entity, ref ReturnOutput returnOutput, string extensionPathName) { string errResult = string.Empty; returnOutput.ErrorCode = "1000"; returnOutput.ErrorMessage = "Ok"; Type t = entity.GetType(); PropertyInfo prop = t.GetProperty("Id"); object retId = prop.GetValue(entity); T data = entity; try { string fullPath = filePath + typeof(T).Name + "\\" + retId.ToString() + ".json"; if (!string.IsNullOrEmpty(extensionPathName)) { fullPath = filePath + typeof(T).Name + "\\" + extensionPathName + "\\" + retId.ToString() + ".json"; } if (File.Exists(fullPath)) { File.Delete(fullPath); string json = JsonConvert.SerializeObject(entity, Formatting.Indented); using (StreamWriter file = File.CreateText(fullPath)) { JsonSerializer serializer = new JsonSerializer(); serializer.Serialize(file, entity); } } else { errResult = "İşlem yapılacak dosya yok. " + fullPath; HelperText.CreateTextFile("UpdateJsonData", errResult); returnOutput.ErrorCode = "1002"; returnOutput.ErrorMessage = errResult; } } catch (Exception ex) { errResult = ex.Message.ToString(); HelperText.CreateTextFile("UpdateJsonData", errResult); returnOutput.ErrorCode = "1001"; returnOutput.ErrorMessage = errResult; } return(data); }
// Write Json // https://www.newtonsoft.com/json/help/html/SerializeWithJsonSerializerToFile.htm public static ReturnOutput WriteJson(T entity, string extensionPathName = "") { ReturnOutput returnOutput = new ReturnOutput(); returnOutput.ErrorCode = "1000"; returnOutput.ErrorMessage = "Ok"; try { int fileId = 0; string sourceFolderPathName = entity.GetType().Name; string json = JsonConvert.SerializeObject(entity, Formatting.Indented); string fullPath = filePath + sourceFolderPathName; if (!string.IsNullOrEmpty(extensionPathName)) { fullPath = fullPath + "\\" + extensionPathName; sourceFolderPathName = sourceFolderPathName + "\\" + extensionPathName; } if (!Directory.Exists(fullPath)) { Directory.CreateDirectory(fullPath); } fullPath = fullPath + "\\" + JsonCoreServices.GetNewFileName(filePath, sourceFolderPathName, ref fileId); Type t = entity.GetType(); PropertyInfo prop = t.GetProperty("Id"); prop.SetValue(entity, fileId, null); using (StreamWriter file = File.CreateText(fullPath)) { JsonSerializer serializer = new JsonSerializer(); serializer.Serialize(file, entity); } } catch (Exception ex) { string result = ex.Message.ToString(); HelperText.CreateTextFile("WriteJson", result); returnOutput.ErrorCode = "1001"; returnOutput.ErrorMessage = result; } return(returnOutput); }
/// <summary> /// Bütün İmageları getirmek için /// </summary> public static void GetReadJsonFile() { ReturnOutput returnOutput = new ReturnOutput(); BasePageActionModel <ContentCategory> baseAction = new BasePageActionModel <ContentCategory>(_dataPath, _logPath); string filePath = _dataPath + "ContentCategory\\4.json"; var result = baseAction.GetReadJsonFileData(filePath, ref returnOutput); Console.WriteLine(result.Count); //List<CountryModel> data = JsonRepositoryService<CountryModel>.ReadJsonAsObjectListAllData("Town_Turkey.json",ref returnOutput); }
public ActionResult Index(int id = 0) { ReturnOutput returnOutput = new ReturnOutput(); if (id > 0)// IsActive = true yap Delete { ControllerPageServices <T, T> .SetDeletedWithUpdate(id, true); } var result = ControllerPageServices <T, T> .GetAllData(""); return(View(result)); }
public static void FindById(int id) { IConnectionFactory connectionFactory = new ConnectionMssql { ConnectionString = connStr }; Repository <Urun> repository = new Repository <Urun>(connectionFactory); ReturnOutput returnOutput = new ReturnOutput(); var result = repository.FindById(2, ref returnOutput); int cnt = 1; }
/// <summary> /// // Read All Json File //https://stackoverflow.com/questions/35431900/get-all-json-files-from-a-folder-and-then-serialize-in-a-single-json-file-usin /// </summary> /// <param name="entity">GetAllJsonData(T entity)</param> /// <returns>List<T></returns> public static List <T> GetReadAllJsonData(string folderName, ref ReturnOutput returnOutput) { returnOutput.ErrorCode = "1000"; returnOutput.ErrorMessage = "Ok"; List <T> list = new List <T>(); string fullPath = filePath + folderName; DirectoryInfo di = new DirectoryInfo(fullPath); try { if (di.GetFiles().Length > 0) { foreach (var file in di.GetFiles()) { using (StreamReader fi = File.OpenText(file.FullName)) { JsonSerializer serializer = new JsonSerializer(); T customer = (T)serializer.Deserialize(fi, typeof(T)); list.Add(customer); } } } else { using (StreamReader fi = File.OpenText(fullPath)) { JsonSerializer serializer = new JsonSerializer(); T customer = (T)serializer.Deserialize(fi, typeof(T)); list.Add(customer); } } } catch (Exception ex) { string result = ex.Message.ToString(); HelperText.CreateTextFile("GetReadAllJsonData", result); returnOutput.ErrorCode = "1001"; returnOutput.ErrorMessage = result; } //finally //{ // return list; //} return(list); }
private T UpdateData(T entity, ref ReturnOutput returnOutput, string extensionPathName) { string jsonFilePath = entity.GetType().Name; string result = string.Empty; // string fullPath = filePath + typeof(T).Name + "\\" + entity + ".json"; JsonRepositoryService <T> jrs = new JsonRepositoryService <T>(filePath, logFilePath); var data = JsonRepositoryService <T> .UpdateJsonData(entity, ref returnOutput, extensionPathName); LogHelper.WriteLog("BasePageActionModel", "UpdateData : " + typeEntity.Name + Environment.NewLine + " ErrorCode = " + returnOutput.ErrorCode + " ErrorMessage = " + returnOutput.ErrorMessage); return(data); }
/// <summary> /// Id ye göre json datayı yakalayıp döndürür /// </summary> /// <param name="id"></param> /// <param name="returnOutput"></param> /// <returns></returns> public T GetDataWithId(int id, ref ReturnOutput returnOutput, string extensionPathName = "") { string jsonFilePath = id.ToString(); if (!string.IsNullOrEmpty(extensionPathName)) { jsonFilePath = extensionPathName + "\\" + id.ToString(); } var result = JsonRepositoryService <T> .ReadJsonAsObject(jsonFilePath, ref returnOutput); LogHelper.WriteLog("BasePageActionModel", "GetDataWithId : " + typeEntity.Name + Environment.NewLine + " Inputs : Id = " + id.ToString() + Environment.NewLine + "ErrorCode = " + returnOutput.ErrorCode + " ErrorMessage = " + returnOutput.ErrorMessage); return(result); }
public ActionResult Form(int id) { T entities = new T(); if (id == 0) { return(View(entities)); } var repository = BaseCommonRepository <T> .BaseRepository(); ReturnOutput returnOutput = new ReturnOutput(); var result = repository.FindById(id, ref returnOutput); return(View()); }
public static void SaveAndUpdate() { // 31.03.2018 00:00:00 ContentCategory contentCategory = new ContentCategory(); contentCategory.ContentCategoryName = "Test"; contentCategory.ContentCategoryDescription = "Test"; contentCategory.StartDate = DateTime.Now; contentCategory.EndDate = DateTime.Now; contentCategory.Id = 0; BasePageActionModel <ContentCategory> baseAction = new BasePageActionModel <ContentCategory>(_dataPath, _logPath); ReturnOutput returnOutput = new ReturnOutput(); var result = baseAction.SaveAndUpdate(contentCategory, ref returnOutput); Console.WriteLine(result); }
public static void Add() { Urun urun = new Urun { Description = "Muz", Price = 10M, CreateDate = DateTime.Now }; IConnectionFactory connectionFactory = new ConnectionMssql { ConnectionString = connStr }; Repository <Urun> repository = new Repository <Urun>(connectionFactory); ReturnOutput returnOutput = new ReturnOutput(); repository.Add(urun, ref returnOutput); }
public static List <T> GetAllData(string whereQuery) { string baseWhereQuery = " Where IsDeleted=0"; if (!string.IsNullOrEmpty(whereQuery)) { baseWhereQuery = whereQuery; } //baseWhereQuery = baseWhereQuery + " AND " + whereQuery; ReturnOutput returnOutput = new ReturnOutput(); var repository = BaseCommonRepository <T> .BaseRepository(); var data = repository.Find(baseWhereQuery, ref returnOutput); return(data.ToList()); }
public static List <TPage> GetAllDataWithMap(string whereQuery) { string baseWhereQuery = " Where IsDeleted=0"; if (!string.IsNullOrEmpty(whereQuery)) { baseWhereQuery = baseWhereQuery + " AND " + whereQuery; } ReturnOutput returnOutput = new ReturnOutput(); var repository = BaseCommonRepository <T> .BaseRepository(); var data = repository.Find(baseWhereQuery, ref returnOutput); var retVal = MappingExtensions.ToModel <T, TPage>(data.ToList()); return(retVal); }
public static T UpdateJsonData(string jsonFilePath, T entity, ref ReturnOutput returnOutput) { string errResult = string.Empty; T data = entity; returnOutput.ErrorCode = "1000"; returnOutput.ErrorMessage = "Ok"; try { string fullPath = filePath + jsonFilePath; if (File.Exists(fullPath)) { File.Delete(fullPath); string json = JsonConvert.SerializeObject(entity, Formatting.Indented); using (StreamWriter file = File.CreateText(fullPath)) { JsonSerializer serializer = new JsonSerializer(); serializer.Serialize(file, entity); } } else { errResult = "İşlem yapılacak dosya yok. " + fullPath; HelperText.CreateTextFile("UpdateJsonData", errResult); returnOutput.ErrorCode = "1002"; returnOutput.ErrorMessage = errResult; } } catch (Exception ex) { errResult = ex.Message.ToString(); HelperText.CreateTextFile("UpdateJsonData", errResult); returnOutput.ErrorCode = "1001"; returnOutput.ErrorMessage = errResult; } return(data); }
/// <summary> /// Json dosya silme işlemi burad File SystemObject ile yapılır. /// </summary> /// <param name="DeleteJsonFile"></param> /// <returns>string jsonFilePath</returns> public static ReturnOutput DeleteJsonFile(string fullPath) { ReturnOutput returnOutput = new ReturnOutput(); returnOutput.ErrorCode = "1000"; returnOutput.ErrorMessage = "Ok"; try { File.Delete(fullPath); } catch (Exception ex) { string result = ex.Message.ToString(); HelperText.CreateTextFile("DeleteJsonFile", result); returnOutput.ErrorCode = "1001"; returnOutput.ErrorMessage = result; } return(returnOutput); }
public ActionResult SaveAndUpdate(T entity) { var repository = BaseCommonRepository <T> .BaseRepository(); ReturnOutput returnOutput = new ReturnOutput(); int id = (int)entity.GetType().GetProperty("Id").GetValue(entity); if (id == 0) { var result = repository.Add(entity, ref returnOutput); } else { repository.Update(entity, ref returnOutput); } ViewBag.Status = returnOutput.ErrorMessage; return(View()); }
public static ReturnOutput SetDeletedWithUpdate(int id, bool isDeleted) { var repository = BaseCommonRepository <T> .BaseRepository(); ReturnOutput returnOutput = new ReturnOutput(); T entity = repository.FindById(id, ref returnOutput); object value = new object(); value = (object)isDeleted; var item = entity.GetType().GetProperty("IsDeleted"); item.SetValue(entity, value); repository = BaseCommonRepository <T> .BaseRepository(); var retVal = repository.Update(entity, ref returnOutput); return(returnOutput); }
public static void AddNew() { ProductCategorys entity = new ProductCategorys { CategoryName = "aa", CreatedBy = 1, LevelOrderNo = 1, CreatedDate = DateTime.Now }; IConnectionFactory connectionFactory = new ConnectionMssql { ConnectionString = connStr }; Repository <ProductCategorys> repository = new Repository <ProductCategorys>(connectionFactory); ReturnOutput returnOutput = new ReturnOutput(); repository.Add(entity, ref returnOutput); }
public T FindById(int id, ref ReturnOutput returnOutput) { string methodName = string.Format("{0}.{1}", MethodBase.GetCurrentMethod().DeclaringType.FullName, MethodBase.GetCurrentMethod().Name); IEnumerable <T> list = null; //returnOutput.ErrorCode = EnumTypes.ErrorCode.Success.ToString(); //returnOutput.ErrorMessage = EnumTypes.ErrorMessages.Ok.ToString(); try { using (var conn = _dbConnection) { list = conn.GetList <T>(new { Id = id }); } } catch (Exception ex) { string errorResult = ex.Message; returnOutput.ErrorCode = EnumTypes.ErrorCode.Error.ToString(); returnOutput.ErrorMessage = errorResult; ReceiverData receiverData = new ReceiverData(); receiverData.Log(methodName, errorResult); } finally { _connectionFactory.GetCloseConnection(_dbConnection); } if (list is null && list.Count() == 0) { return(null); } return(list.FirstOrDefault()); }
/// <summary> /// https://stackoverflow.com/questions/17817407/generic-method-return-type-as-type-parameter /// </summary> public T SaveAndUpdate(T entity, ref ReturnOutput returnOutput, string extensionPathName = "") { T retData = entity; Type t = entity.GetType(); PropertyInfo prop = t.GetProperty("Id"); object retId = prop.GetValue(entity); if (!ReferenceEquals(retId, null) && (int)retId > 0) { // Log işlemi yap var retValUpdate = UpdateData(entity, ref returnOutput, extensionPathName); } else { LogHelper.WriteLog("SaveAndUpdate", "InsertData"); var result = SaveData(entity, extensionPathName); returnOutput = result; } return(retData); }
/// Json dosya taşıma işlemi burad File SystemObject ile yapılır. /// typeName demek Contenet demek Model in Classın adı demek public static ReturnOutput MoveJsonFile(string fullPath, string destinationPath) { ReturnOutput returnOutput = new ReturnOutput { ErrorCode = "1000", ErrorMessage = "Ok" }; try { FileInfo fi = new FileInfo(fullPath); File.Move(fullPath, destinationPath); } catch (Exception ex) { string result = ex.Message.ToString(); HelperText.CreateTextFile("MoveJsonFile", result); returnOutput.ErrorCode = "1001"; returnOutput.ErrorMessage = result; } return(returnOutput); }
public static List <T> GetReadAllJsonData(string folderName, int pageCount, int showDataCount, string sortName, ref ReturnOutput returnOutput) { returnOutput.ErrorCode = "1000"; returnOutput.ErrorMessage = "Ok"; List <T> list = new List <T>(); string fullPath = filePath + folderName; DirectoryInfo di = new DirectoryInfo(fullPath); int fileStartCount = ((pageCount * showDataCount) - showDataCount) + 1; // 11 int fileFinishCount = pageCount * showDataCount; // if (fileFinishCount > di.GetFiles().Length) { fileFinishCount = di.GetFiles().Length; } //var data = di.GetFiles().OrderBy(s => s.FullName); //Where(s => s.FullName == fileStartCount.ToString() + ".json"); try { foreach (var file in di.GetFiles()) { using (StreamReader fi = File.OpenText(file.FullName)) { JsonSerializer serializer = new JsonSerializer(); T customer = (T)serializer.Deserialize(fi, typeof(T)); list.Add(customer); } } } catch (Exception ex) { string result = ex.Message.ToString(); HelperText.CreateTextFile("GetReadAllJsonData", result); returnOutput.ErrorCode = "1001"; returnOutput.ErrorMessage = result; } //finally //{ // return list; //} return(list); }