public bool Submit(SubmitCodeModel submitCodeModel) { User currentUser = helper.GetCurrentUser(HttpContext.Current.Session["UserId"]); if (currentUser == null) { return(false); } currentUser.Code = submitCodeModel.Code.Replace("%2B", "+"); context.SaveChanges(); return(true); }
public object Register(RegisterModel addUserModel) { User userWithSameLogin = repository.Users .Where(u => u.Login == addUserModel.Login) .FirstOrDefault(); if (userWithSameLogin != null) { return new { error = "The username already taken" } } ; if (addUserModel.Password != addUserModel.PasswordRepeat) { return new { error = "Passwords does not match" } } ; if (addUserModel.Password.Length < 3) { return new { error = "Password too short" } } ; DBUser user = new DBUser(); user.Username = addUserModel.Login; user.PasswordHash = helper.CreateHash(addUserModel.Password); user.ShipPresetId = 1; user.Code = ""; user.CellTypes = new PresetShipRepository() .GetShip(user.ShipPresetId) .DefaultLayout; context.Users.Add(user); context.SaveChanges(); repository.UpdateFromDB(context); return(new { success = true }); } } }