public ResultData <List <TEntry> > _search(Expression <Func <TEntry, bool> > where)
        {
            var db = new ClassAppContext();

            try
            {
                var result = db.Set <TEntry>().Where(where).ToList();
                return(ResultData <List <TEntry> > .Instance.Fill(true, result));
            }
            catch (Exception ex)
            {
                return(ResultData <List <TEntry> > .Instance.Fill(false, "İşlem yapılırken hata oluştu" + ex.ToString()));
            }
        }
        public ResultData <TEntry> _getByID(int id)
        {
            var db = new ClassAppContext();

            try
            {
                var result = db.Set <TEntry>().Find(id);
                return(ResultData <TEntry> .Instance.Fill(true, result));
            }
            catch (Exception ex)
            {
                return(ResultData <TEntry> .Instance.Fill(false, "İşlem yapılırken hata oluştu" + ex.ToString()));
            }
        }
        public ResultData <User> GetProfileInfo(int _userid)
        {
            var db = new ClassAppContext();

            var user = db.User.FirstOrDefault(a => a.UserID == _userid);

            if (user != null)
            {
                return(ResultData <User> .Instance.Fill(true, user));
            }
            else
            {
                return(ResultData <User> .Instance.Fill(false, "Kullanıcı Bulunamdı"));
            }
        }
Exemple #4
0
        public bool AddLessonComment(LessonComment comment)
        {
            var db = new ClassAppContext();

            try
            {
                var added = db.LessonComment.Add(comment);
                db.SaveChanges();
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
 public ResultData <TEntry> _insert(TEntry entry)
 {
     using (var db = new ClassAppContext())
     {
         try
         {
             var addedEntry = db.Set <TEntry>().Add(entry);
             db.SaveChanges();
             return(ResultData <TEntry> .Instance.Fill(true, addedEntry));
         }
         catch (Exception ex)
         {
             return(ResultData <TEntry> .Instance.Fill(false, "İşlem yapılırken hata oluştu" + ex.ToString()));
         }
     }
 }
        public ResultData <bool> _delete(TEntry entry)
        {
            var db = new ClassAppContext();

            try
            {
                db.Set <TEntry>().Remove(entry);
                db.SaveChanges();

                return(ResultData <bool> .Instance.Fill(true, true));
            }
            catch (Exception ex)
            {
                return(ResultData <bool> .Instance.Fill(false, "İşlem yapılırken hata oluştu." + ex.ToString()));
            }
        }
        public ResultData <TEntry> _update(TEntry entry)
        {
            var db = new ClassAppContext();

            try
            {
                var updatedEntry = db.Set <TEntry>().Attach(entry);
                var up           = db.Entry(updatedEntry);
                up.State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
                return(ResultData <TEntry> .Instance.Fill(true, updatedEntry));
            }
            catch (Exception ex)
            {
                return(ResultData <TEntry> .Instance.Fill(false, "İşlem yapılırken hata oluştu" + ex.ToString()));
            }
        }
Exemple #8
0
        public ResultData <Lesson> Join(string code, int userid)
        {
            try
            {
                var db = new ClassAppContext();

                var lesson = db.Lesson.FirstOrDefault(a => a.LessonCode == code.Trim());

                if (lesson != null)
                {
                    var control = lesson.LessonAccess.Count(b => b.UserID == userid);

                    if (control > 0)
                    {
                        return(ResultData <Lesson> .Instance.Fill(false, "Ders Zaten Alınmış"));
                    }
                    else
                    {
                        var db2 = new ClassAppContext();


                        db.Entry(lesson).Collection(z => z.LessonAccess).Load();
                        lesson.LessonAccess.Add(new LessonAccess()
                        {
                            User = db.User.Single(a => a.UserID == userid)
                        });

                        db.SaveChanges();



                        return(ResultData <Lesson> .Instance.Fill(true, lesson));
                    }
                }
                else
                {
                    return(ResultData <Lesson> .Instance.Fill(false, "hata oluştu"));
                }
            }
            catch (Exception ex)
            {
                return(ResultData <Lesson> .Instance.Fill(false, "hata oluştu" + ex.Message));
            }
        }
 public BaseRepository()
 {
     db = new ClassAppContext();
 }
Exemple #10
0
        public List <LessonContent> GetLessonContent(int lessonID)
        {
            var db = new ClassAppContext();

            return(db.LessonContent.Where(l => l.LessonID == lessonID).OrderByDescending(a => a.RecordDate)?.ToList());
        }