public string GetData(string value) { using (var db = new whatshotEntities1()) { var userCount = db.Users.Count(); var newuser = new User() { Id = userCount + 1, UserName = "******", DefaultLocation = "", HashedPassword = "" }; db.Users.Add(newuser); db.SaveChanges(); return "success"; } }
public string Register(string user, string password, string defaultlocation) { int userId; double lat, loong; if (!LocationHelper.IsPostcode(defaultlocation) && !(LocationHelper.IsLatLong(defaultlocation,out lat, out loong))) return ""; // check if user already exists using (var db = new whatshotEntities1()) { var userExists = (from User in db.Users where User.UserName == user select User).Any(); if (userExists) return ""; var newUser = new User() { UserName = user, HashedPassword = password, DefaultLocation = defaultlocation }; db.Users.Add(newUser); db.SaveChanges(); userId = newUser.Id; } return _tokenHelper.CreateToken(userId); }