예제 #1
0
        public async Task <string> CreateUserAsync(PostUser user)
        {
            var    dbUser   = _PostUsertoDB(user);
            string cityName = await repository.CreateUserAsync(dbUser);

            return(cityName);
        }
예제 #2
0
        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();
            }));
        }
예제 #5
0
 public object ValidationCode(PostUser phoneCode)
 {
     if (phoneCode == null)
     {
         return(new ReturnResult <bool>(-2, "参数传入错误"));
     }
     return(_SystemService.ValidationCode(phoneCode.PhoneNumber, phoneCode.VerificationCode));
 }
예제 #6
0
 private User _PostUsertoDBUser(PostUser user)
 {
     return(new User
     {
         CityName = user.CityName,
         Name = user.Name
     });
 }
예제 #7
0
 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));
 }
예제 #8
0
 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));
 }
예제 #9
0
        public async Task <IActionResult> AuhorizeUser([FromBody] PostUser model)
        {
            var token = await authService.AuthorizeUser(new UserCredentials()
            {
                Email = model.Email, Password = model.Password
            });

            return(Ok(token));
        }
예제 #10
0
        public object AddUserSendMessage(PostUser phone)
        {
            var isExist = _UsersService.ExistsUserByPhoneNumber(phone.PhoneNumber);

            if (isExist)
            {
                return(new ReturnResult <bool>(-2, "手机号已经被使用,请更换!"));
            }
            return(_SystemService.SendMobileMessage(phone.PhoneNumber));
        }
예제 #11
0
 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));
 }
예제 #12
0
        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"));
        }
예제 #14
0
        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);
        }
예제 #15
0
 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));
 }
예제 #16
0
        // 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));
        }
예제 #17
0
        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));
        }
예제 #18
0
 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);
     }
 }
예제 #19
0
        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);
        }
예제 #20
0
        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"));
        }
예제 #22
0
        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"));
            }
        }
예제 #23
0
        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");
            }
        }
예제 #24
0
        /// <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);
        }
예제 #25
0
        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));
            }
        }
예제 #26
0
        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;
        }
예제 #27
0
        /// <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));
        }
예제 #28
0
        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();
            }
        }
예제 #29
0
        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));
        }
예제 #30
0
        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));
        }