public async Task <string> CreateUserAsync(PostUser user) { var dbUser = _PostUsertoDB(user); string cityName = await repository.CreateUserAsync(dbUser); return(cityName); }
public async Task <IHttpActionResult> PostPost(Post post) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var userid = User.Identity.GetUserId <string>(); // var post = postvm.Post; post.CreateTime = DateTime.UtcNow; db.Posts.Add(post); PostUser pu = new PostUser() { IsOnDuty = true, PostDate = DateTime.UtcNow, PosterID = post.CreaterId, PostId = post.Id, UserId = post.UserId }; checkRole(post.UserId); db.PostUsers.Add(pu); try { await db.SaveChangesAsync(); } catch (DBConcurrencyException) { throw; } post.PostUsers = null; return(CreatedAtRoute("DefaultApi", new { id = post.Id }, post)); }
public IHttpActionResult PostUser(PostUser postUser) { using (var db = new AndroidCaseCompetitionEntities()) { var user = db.Users .Include(x => x.Subject) .Include(x => x.UserType) .FirstOrDefault(x => x.Name == postUser.Name && x.Password == postUser.Password); if (user == null) { return(NotFound()); } return(Ok(new { user.Id, user.Name, user.Password, user.UserTypeId, UserTypeName = user.UserType.Name, user.SubjectId })); } }
public Task AddPostToUserNewsfeed(Post post) { return(Task.Run(() => { List <string> Subscribers = GetSubscribers(post); if (Subscribers.Count <= 0) { return; } foreach (var sub in Subscribers) { try { PostUser postUser = new PostUser(); postUser.PostId = post.PostId; postUser.UserId = sub; _repo.PostUser.Create(postUser); } catch { // If implement ILogger later, log. Console.WriteLine($"{sub} did not recieve {post.PostTitle}, #{post.PostId}."); } } _repo.Save(); })); }
public object ValidationCode(PostUser phoneCode) { if (phoneCode == null) { return(new ReturnResult <bool>(-2, "参数传入错误")); } return(_SystemService.ValidationCode(phoneCode.PhoneNumber, phoneCode.VerificationCode)); }
private User _PostUsertoDBUser(PostUser user) { return(new User { CityName = user.CityName, Name = user.Name }); }
public object Login(PostUser user) { if (user == null || string.IsNullOrEmpty(user.LoginName) || string.IsNullOrEmpty(user.Pwd)) { return(new ReturnResult <Users>(-4, "传入参数错误!")); } return(_UsersService.Login(user.LoginName, user.Pwd)); }
public object ChangePassword(PostUser pwd) { if (pwd == null || string.IsNullOrEmpty(pwd.Id) || string.IsNullOrEmpty(pwd.OldPwd) || string.IsNullOrEmpty(pwd.NewPwd)) { return(new ReturnResult <bool>(-4, "传入参数错误!")); } return(_UsersService.ChangePassword(pwd.Id, pwd.OldPwd, pwd.NewPwd)); }
public async Task <IActionResult> AuhorizeUser([FromBody] PostUser model) { var token = await authService.AuthorizeUser(new UserCredentials() { Email = model.Email, Password = model.Password }); return(Ok(token)); }
public object AddUserSendMessage(PostUser phone) { var isExist = _UsersService.ExistsUserByPhoneNumber(phone.PhoneNumber); if (isExist) { return(new ReturnResult <bool>(-2, "手机号已经被使用,请更换!")); } return(_SystemService.SendMobileMessage(phone.PhoneNumber)); }
public object ChangePasswordByPhoneNumber(PostUser newPwd) { if (newPwd == null || string.IsNullOrEmpty(newPwd.PhoneNumber) || string.IsNullOrEmpty(newPwd.NewPwd) || string.IsNullOrEmpty(newPwd.VerificationCode)) { return(new ReturnResult <bool>(-4, "传入参数错误!")); } return(_UsersService.ChangePasswordByPhoneNumber(newPwd.PhoneNumber, newPwd.NewPwd, newPwd.VerificationCode)); }
public async Task <bool> CreateUser(PostUser postUser) { Console.WriteLine("Creating user"); var request = GenerateRequest(postUser); var response = await _client.PostAsync(UsersUri, request); LogResponse(response); return(response.IsSuccessStatusCode); }
public IActionResult UserPostLikeToggle(int id) { var userId = _userManager.GetUserId(User); PostUser postUser = _repo.PostUser.GetPostUserEntry(userId, id); postUser.IsLiked = !postUser.IsLiked; _repo.PostUser.Update(postUser); _repo.Save(); return(View("Newsfeed")); }
private User _PostUsertoDB(PostUser user) { User dbUser = new User { CityName = user.CityName, Name = user.Name, Password = _GetHashedTextString(user.Password), AccessToken = _BuildToken(user.Name, user.CityName) }; return(dbUser); }
public object AddUser(PostUser user) { if (user == null) { return(new ReturnResult <Users>(-4, "传入参数错误!")); } if (user == null || string.IsNullOrEmpty(user.VerificationCode) || string.IsNullOrEmpty(user.Pwd) || string.IsNullOrEmpty(user.PhoneNumber)) { return(new ReturnResult <Users>(-4, "传入参数错误!")); } return(_UsersService.AddUser(user.PhoneNumber, user.Pwd, user.VerificationCode)); }
// GET: Post/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PostUser post = postService.GetById((int)id); if (post == null) { return(HttpNotFound()); } return(View(post)); }
public object ChangePwdSendMessage(PostUser phone) { if (phone == null) { return(new ReturnResult <bool>(-2, "参数传入错误")); } var isExist = _UsersService.ExistsUserByPhoneNumber(phone.PhoneNumber); if (!isExist) { return(new ReturnResult <bool>(-2, "手机号未注册!")); } return(_SystemService.SendMobileMessage(phone.PhoneNumber)); }
public string CreateUser(PostUser user) { using (var sqlConnection = Application.Program.sqlHandler.GetConnection()) { var userList = new List <DbUser>(); sqlConnection.Open(); var command = new SqlCommand(); command.Connection = sqlConnection; command.CommandText = @"SELECT count(*) FROM T_USER"; command.ExecuteNonQuery(); string AccessToken = ""; return(AccessToken); } }
public void CreateUser() { Console.WriteLine("Username:"******"Email:"); var email = Console.ReadLine(); var password = CreatePassword(); var request = new PostUser(username, email, password); var response = _api.CreateUser(request); Console.WriteLine("User created: " + response); }
public IActionResult Login(PostUser user) { var customer = this.TestDB.Customers.FirstOrDefault(p => p.UserName == user.UserName && p.Password == user.Password); if (customer != null) { customer.AccessToken = CreateAuthToken(user.UserName, "Public"); this.TestDB.SaveChanges(); return(Ok(customer)); } else { return(BadRequest("Invalid User")); } }
public IActionResult RemovePostFromFeed(int id) { var userId = _userManager.GetUserId(User); PostUser postUser = _repo.PostUser.GetPostUserEntry(userId, id); _repo.PostUser.Delete(postUser); _repo.Save(); if (!_signInManager.IsSignedIn(User)) { return(RedirectToAction("Index")); } return(View("Newsfeed")); }
public ActionResult Create(PostUser p, HttpPostedFileBase file) { { p.date_publication = DateTime.Now; p.Picture = file.FileName; postService.Add(p); postService.Commit(); var fileName = ""; if (file.ContentLength > 0) { var path = Path.Combine(Server.MapPath("~/Content/Upload/"), file.FileName); file.SaveAs(path); } return(RedirectToAction("Index")); } }
public void TestSave() { WeighInUser actualUser = null; Mock <IDynamoDBContext> context = new Mock <IDynamoDBContext>(); context.Setup(C => C.SaveAsync <WeighInUser>(It.IsAny <WeighInUser>(), It.IsAny <CancellationToken>())).Returns((WeighInUser user, object t) => { actualUser = user; return(Task.CompletedTask); }); TestAwsFactory factory = new TestAwsFactory() { DynamoDBContext = context.Object }; WeighInUser testUser = new WeighInUser() { UserId = "TestUserId", FirstName = "Unit", StartingWeight = 88.8m, StartingWeightDate = new DateTime(2018, 7, 16) }; string testUserJson = JsonConvert.SerializeObject(testUser); using (PostUser postUser = new PostUser(factory)) { string userOutputJson = postUser.Save(testUserJson); Assert.That(actualUser, Is.Not.Null, "actualUser"); Assert.That(actualUser.UserId, Is.EqualTo("TestUserId"), "actualUserId"); Assert.That(actualUser.FirstName, Is.EqualTo("Unit"), "actualFirstName"); Assert.That(actualUser.StartingWeight, Is.EqualTo(88.8m), "actualStartingWeight"); Assert.That(actualUser.StartingWeightDate, Is.EqualTo(new DateTime(2018, 7, 16)), "actualStartingWeightDate"); Assert.That(actualUser.UserKey, Is.Not.Null.And.Not.Empty, "actualUserKey"); dynamic user = JObject.Parse(userOutputJson); Assert.That((string)user.UserId, Is.EqualTo("TestUserId"), "UserId"); Assert.That((string)user.FirstName, Is.EqualTo("Unit"), "FirstName"); Assert.That((decimal)user.StartingWeight, Is.EqualTo(88.8m), "StartingWeight"); Assert.That((DateTime)user.StartingWeightDate, Is.EqualTo(new DateTime(2018, 7, 16)), "StartingWeightDate"); Assert.That((string)user.UserKey, Is.Not.Null.And.Not.Empty, "UserKey"); } }
/// <summary> /// The post. /// </summary> /// <returns> /// The <see cref="GetUser"/>. /// </returns> private GetUser Post() { // Arrange var user = new PostUser() { Username = RandomGenerator.GetRandomString(10), Password = RandomGenerator.GetRandomString(10) }; // Act var response = Client.PostAsJsonAsync(Resources.Users, user).Result; // Assert Assert.AreEqual(HttpStatusCode.Created, response.StatusCode, "POST user not ok."); return(response.Content.ReadAsAsync <GetUser>().Result); }
public async Task <IActionResult> Post([FromBody] PostUser test) { try { var result = await _userManager.CreateAsync(new ApplicationUser { Email = test.Email, UserName = test.Email }, test.Password); return(Ok(result)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task PostUserPositiveTest() { var expectedAuthor = new PostUser { FirstName = null, LastName = "test2", HouseholdId = 1, }; var content = new StringContent(expectedAuthor.ToJson(), Encoding.UTF8, "application/json"); var response = await _client.PostAsync("/users", content); response.EnsureSuccessStatusCode(); var responseAsString = response.Content.ReadAsStringAsync().Result; }
/// <summary> /// The post. /// </summary> /// <param name="item"> /// The item. /// </param> /// <returns> /// The <see cref="HttpResponseMessage"/>. /// </returns> /// <remarks> /// POST users /// </remarks> public HttpResponseMessage Post(PostUser item) { var user = new User() { Username = item.Username, Password = EncryptedString.Create(item.Password, _encryptionService) }; if (user.IsValid) { _userDataMapper.Insert(user); GetUser createdItem = _mapper.Map <User, GetUser>(user); return(CreatedHttpResponse(createdItem.ID, createdItem)); } return(Request.CreateResponse(HttpStatusCode.BadRequest, user.ValidationErrors)); }
public void CreateUserPost(String PostId, String UserId) { // First is needed to check if the relation alredy exist var Relation = db.PostUsers.Where(x => x.Fk_Post == PostId && x.Fk_User == UserId).Select(x => x.PostUserID); if (Relation.Count() == 0 && PostId != null && UserId != null) { GenerateId generator = new GenerateId(); PostUser postRelation = new PostUser(); postRelation.PostUserID = generator.generateID(); postRelation.Fk_Post = PostId; postRelation.Fk_User = UserId; db.PostUsers.Add(postRelation); db.SaveChanges(); } }
public object UpdateUserByKey(PostUser user) { if (user == null || string.IsNullOrEmpty(user.Id) || string.IsNullOrEmpty(user.KeyName)) { return(new ReturnResult <Users>(-4, "传入参数错误!")); } var userTemp = _UsersService.GetOne(p => p.id == user.Id); switch (user.KeyName) { case "avatar": userTemp.avatar = user.KeyValue; break; case "nickname": userTemp.nickname = user.KeyValue; break; case "area": userTemp.area = user.KeyValue; break; case "organization": userTemp.organization = user.KeyValue; break; case "profession": userTemp.profession = user.KeyValue; break; case "signatures": userTemp.signatures = user.KeyValue; break; case "position": userTemp.position = user.KeyValue; break; default: return(new ReturnResult <bool>(-2, "未找到待更新的字段名称!")); } return(_UsersService.UpdateUser(userTemp)); }
public IActionResult CreateUser([FromBody] PostUser model) { if (ModelState.IsValid) { var command = new AddUser(model.Email, model.Password); commandBus.AddCommand(command); commandBus.InvokeCommandsQueue(); var result = GetUserDetails(command.Id); return(CreatedAtRoute( "GetUser", new { userEmail = command.Email }, result.Data )); } return(BadRequest(ModelState)); }