コード例 #1
0
 //Update
 public static void UpdateLastLocation(LastLocation l)
 {
     try
     {
         using (RatzhKatzviEntities1 db = new RatzhKatzviEntities1())
         {
             try
             {
                 LastLocation isExist = db.LastLocation.FirstOrDefault(x => x.UserId == l.UserId);
                 if (isExist != null)
                 {
                     db.LastLocation.AddOrUpdate(l);
                     //db.Entry(l).State = EntityState.Modified;
                     db.SaveChanges();
                 }
             }
             catch (Exception ex)
             {
                 Console.WriteLine(ex);
             }
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
     }
 }
コード例 #2
0
 //Delete
 public static void DeleteLastLocation(LastLocation l)
 {
     if (l.Id != 0)
     {
         using (RatzhKatzviEntities1 db = new RatzhKatzviEntities1())
         {
             try
             {
                 //LastLocation isExist = db.LastLocation.FirstOrDefault(x => x == l);
                 //db.LastLocation.Remove(isExist);
                 db.Entry(l).State = EntityState.Deleted;
                 db.LastLocation.Remove(l);
                 db.SaveChanges();
             }
             catch (Exception ex) { }
         }
     }
 }
コード例 #3
0
 //Add
 public static void AddLastLocation(LastLocation l)
 {
     try
     {
         using (RatzhKatzviEntities1 db = new RatzhKatzviEntities1())
         {
             LastLocation isExist = db.LastLocation.FirstOrDefault(x => x.UserId == l.UserId);
             if (isExist == null)
             {
                 db.LastLocation.Add(l);
                 db.SaveChanges();
             }
             else
             {
                 UpdateLastLocation(l);
             }
         }
     }
     catch (Exception ex) { }
 }