Esempio n. 1
0
        // Yeni öğrenci oluşturuyor.
        public static (mStudent createdStd, bool error) StudentCreate(mStudent cacheStd = null)
        {
            // cacheStd null ise yeni nesne oluşturyor dolu ise cacheStd yi kopyalıyor.
            mStudent std = cacheStd ?? new mStudent();

            // Daha değer atanmamış mStudent propertilerini seçiyor.
            var emptyStdProperty = std.GetType().GetProperties().Where(x => x.GetValue(std) == null);
            // kullanıcın girdiği değerler validate işleminden geçirildikten sonra propertysinin türüne göre
            object output;

            foreach (var stdProp in emptyStdProperty)
            {
                string propName = stdProp.Name;
                Console.Write(propName + ": ");
                output = null;
                // kullanıcının girdiği değerin property türü ile uyuşmasını kontrol ediyor ve dönüştürülen değeri output a atıyor.
                bool validate = Validate.StudentProperty(Console.ReadLine(), propName, ref output);
                if (validate)
                {
                    // mStudent den oluşturulan std nesnesinin stdProp propertisine kullanıcının girdiği değeri atıyor.
                    stdProp.SetValue(std, output);
                }
                else // girilen değer property nin türüne çevrilemiyorsa geri dönüyor.
                {
                    return(std, true);
                }
            }
            return(std, false);
        }
        // dosyanın içeriğine yeni veri ekleniyor
        public static void AppendFile(mStudent data, string fileName)
        {
            string          path     = dbPath(fileName);
            List <mStudent> fileJson = ReadFile(path);

            fileJson.Add(data);
            // Indented verileri tek satır yerine girintili olarak yazdırıyor.
            var serialize = JsonConvert.SerializeObject(fileJson, Formatting.Indented);

            File.WriteAllText(path, serialize);
        }
Esempio n. 3
0
 public static void ShowStudentToUser(mStudent std)
 {
     Console.Clear();
     Console.WriteLine(std);
     Console.WriteLine();
 }
Esempio n. 4
0
 public static void WriteCacheStd(mStudent std)
 {
     std.FilledProperty().ForEach(Console.WriteLine);
 }