public void Start() { using (var dbEntities = new DBEntities()) { } }
public bool Add(PointModel pointModel) { using (var dbEntities = new DBEntities()) { try { dbEntities.Points.Add(new Point() { UserID = 11, X = pointModel.X, Y = pointModel.Y, Z = pointModel.Z, vX = pointModel.Xv, vY = pointModel.Yv, vZ = pointModel.Zv, Date = DateTime.Now }); dbEntities.SaveChanges(); return true; } catch (Exception) { return false; } } }
public int GetUserIdByName(string firstName, string lastName) { using (var dbEntities = new DBEntities()) { return dbEntities.Users.First(p => p.FirstName == firstName && p.LastName == lastName).Id; } }
public int GetCurrentUserId(string login) { using (var dbEntities = new DBEntities()) { return dbEntities.Credentials.First(p => p.Login == login).UserID; } }
public bool Login(string login, string password) { using (var dbEntities = new DBEntities()) { string encryptedPassword = CryptoHelper.Encrypt(password); return dbEntities.Credentials.FirstOrDefault(p => p.Login == login && p.Password == encryptedPassword) != null; } }
public UserModel GetUserById(int id) { using (var dbEntities = new DBEntities()) { User user = dbEntities.Users.FirstOrDefault(p => p.Id == id); return new UserModel() { UserId = user.Id, Address = user.Address, Birthday = user.Birthday, FirstName = user.FirstName, LastName = user.LastName, Mobile = user.Mobile }; } }
public bool Remove(CredentialsModel credentials) { using (var dbEntities = new DBEntities()) { try { dbEntities.Credentials.Remove(new Credential() { Id = credentials.Id, UserID = credentials.UserId, Login = credentials.Login, Password = credentials.Password }); dbEntities.SaveChanges(); return true; } catch (Exception exception) { return false; } } }
public bool Add(int userId, string login, string password) { using (var dbEntities = new DBEntities()) { try { dbEntities.Credentials.Add(new Credential() { Login = login, Password = CryptoHelper.Encrypt(password), UserID = userId }); dbEntities.SaveChanges(); return true; } catch (Exception exception) { return false; } } }
public IEnumerable<PointModel> GetAllPoint(int id) { using (var dbEntities = new DBEntities()) { return dbEntities.Points.Where(w => w.UserID == id).Select(p => new PointModel() { //User = p.UserID, X = p.X, Y = p.Y, Z = p.Z, Xv = p.vX, Yv = p.vY, Zv = p.vZ, Date = p.Date }).ToArray(); } }
public int Add(UserModel userModel) { using (var dbEntities = new DBEntities()) { try { dbEntities.Users.Add(new User() { FirstName = userModel.FirstName, LastName = userModel.LastName, Mobile = userModel.Mobile, Address = userModel.Address, Birthday = userModel.Birthday }); dbEntities.SaveChanges(); return GetUserIdByName(userModel.FirstName, userModel.LastName); } catch (Exception e) { return 0; } } }