/// <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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        // 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);
        }
Esempio n. 8
0
        /// <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));
        }
Esempio n. 10
0
        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;
        }
Esempio n. 11
0
        /// <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);
        }
Esempio n. 14
0
        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());
        }
Esempio n. 15
0
        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);
        }
Esempio n. 16
0
        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);
        }
Esempio n. 17
0
        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());
        }
Esempio n. 18
0
        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);
        }
Esempio n. 19
0
        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);
        }
Esempio n. 20
0
        /// <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);
        }
Esempio n. 21
0
        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());
        }
Esempio n. 22
0
        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);
        }
Esempio n. 23
0
        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);
        }
Esempio n. 24
0
        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);
        }
Esempio n. 26
0
        /// 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);
        }
Esempio n. 27
0
        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);
        }