Example #1
0
        public virtual void Remove(int entityId)
        {
            var ctx    = new ProjeHaberDbEntities();
            T   Entity = ctx.Set <T>().Find(entityId);

            ctx.SaveChanges();
            if (ctx.Entry(Entity).State == EntityState.Detached)
            {
                ctx.Set <T>().Attach(Entity);
            }
            ctx.Set <T>().Remove(Entity);
            ctx.SaveChanges();
        }
Example #2
0
        public virtual void Add(T entity)
        {
            var ctx = new ProjeHaberDbEntities();

            ctx.Set <T>().Add(entity);
            ctx.SaveChanges();
        }
Example #3
0
        public virtual void Update(T entity)
        {
            var ctx = new ProjeHaberDbEntities();

            ctx.Set <T>().Attach(entity);
            ctx.Entry(entity).State = EntityState.Modified;
            ctx.SaveChanges();
        }
Example #4
0
        public void ReadCount(int id)
        {
            var      ctx      = new ProjeHaberDbEntities();
            HaberTbl haberTbl = ctx.HaberTbl.FirstOrDefault(c => c.Id == id);

            if (haberTbl.ReadCount == null)
            {
                haberTbl.ReadCount = 1;
            }
            else
            {
                haberTbl.ReadCount++;
            }
            ctx.SaveChanges();
        }
Example #5
0
        public int UploadImageInDataBase(HttpPostedFileBase file, Image image)
        {
            image.Data = ConvertToBytes(file);
            var images = new Image
            {
                Name    = image.Name,
                FileUrl = image.FileUrl,
                Data    = image.Data
            };
            var ctx = new ProjeHaberDbEntities();

            ctx.Image.Add(images);
            int i = ctx.SaveChanges();

            if (i == 1)
            {
                return(1);
            }
            else
            {
                return(0);
            }
        }