//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); } }
//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) { } } } }
//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) { } }