private Session saveSession(User userEntity) { using (CompanyPosDBContext database = new CompanyPosDBContext()) { Session session = (database.Sessions.ToList().FirstOrDefault(x => x.UserID == userEntity.ID)); if (session == null) { session = new Session(); //Save Session session.StoreID = userEntity.StoreID; session.TokenID = DateTime.Now.GetHashCode().GetHashCode().ToString() + session.StoreID; session.UserID = userEntity.ID; session.Created = DateTime.Now; session.LastUpdate = session.Created; database.Sessions.Add(session); } else { session.StoreID = userEntity.StoreID; session.TokenID = DateTime.Now.GetHashCode().GetHashCode().ToString() + session.StoreID; session.UserID = userEntity.ID; session.LastUpdate = DateTime.Now; //not add because us an Update //database.Sessions.Add(session); database.Entry(session).State = System.Data.Entity.EntityState.Modified; //2. call SaveChanges database.SaveChanges(); } return(session); } }
private void removeDispositive(string UUID, int UserID) { using (CompanyPosDBContext database = new CompanyPosDBContext()) { var dispositives = (from disp in database.Dispositives where disp.UUID.Equals(UUID) && disp.UserID.Equals(UserID) select disp).ToList(); foreach (var disp in dispositives) { //1. set values disp.Active = false; //2. Mark entity as modified database.Entry(disp).State = System.Data.Entity.EntityState.Modified; //2. call SaveChanges database.SaveChanges(); } } }