Пример #1
0
 public void AddGroup(GroupModel entity)
 {
     using (var db = new EFWorkContext())
     {
         db.Group.Add(entity);
         db.SaveChanges();
     }
 }
Пример #2
0
        public async Task <ActionResult> AddOrUpdate(DeviceDataModel d)
        {
            using (var db = new EFWorkContext())
            {
                var dd = await db.DeviceData.AsNoTracking().Where(a => a.Name == d.Name).FirstOrDefaultAsync();//.FirstOrDefault();

                if (dd == null)
                {
                    dd = db.DeviceData.Add(d);
                }
                else
                {
                    dd.Message = d.Message;
                    dd.Dt      = DateTime.Now;
                    db.Entry <DeviceDataModel>(dd).State = EntityState.Modified;
                }
                db.SaveChanges();
                return(Json(new { dd.DeviceId }));
            }
        }