public void RemoveFromEvent(string str) { User user = JsonConvert.DeserializeObject <User>(str); using (var context = new EventNetContext()) { foreach (var existEvent in context.Events) { if (existEvent.Beacon.UUID == user.Event.Beacon.UUID) { existEvent.Users.Remove(user); context.SaveChanges(); } } } }
public string SignUp(string str) { if (str != null) { User newUser = JsonConvert.DeserializeObject <User>(str); if (newUser != null) { if (!Regex.Match(newUser.Email, @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$").Success) { return("ERROR! Invalid e-mail address."); } if (newUser.Name == null) { return("ERROR! Please enter your name!"); } using (var context = new EventNetContext()) { List <User> users = context.Users.ToList(); foreach (var user in users) { if (user.Email == newUser.Email) { return("ERROR! This e-mail already existst."); } } context.Users.Add(newUser); context.SaveChanges(); return(JsonConvert.SerializeObject(newUser)); } } else { return("ERROR! Please send the user data."); } } else { return("ERROR! Argument is null"); } }