Beispiel #1
0
        public UserInfoOutput GetDetailBySessionId([FromBody] UserInfoInput input)
        {
            UserInfoOutput output = new UserInfoOutput();

            if (input == null)
            {
                output.Result = "INPUT_IS_NULL";
            }
            else
            {
                AppLoginSession session = _db.AppLoginSessions.Where(e => e.Id.Equals(input.SessionId) && e.Status == 1).FirstOrDefault();

                if (session == null)
                {
                    output.Result = "SESSION_NOT_EXIST";
                }
                else
                {
                    if (session.Key.Equals(input.SessionKey))
                    {
                        User                     user      = session.User;
                        List <Order>             orders    = user.ListOrders.Where(e => e.Deleted == false).OrderByDescending(e => e.DateCreated).ToList();
                        List <OrderPreviousItem> newOrders = new List <OrderPreviousItem>();
                        NumberFormatInfo         nfi       = new CultureInfo("ms-MY", false).NumberFormat;
                        nfi.CurrencyDecimalDigits = 2;

                        foreach (Order item in orders)
                        {
                            OrderPreviousItem newItem = new OrderPreviousItem()
                            {
                                OrderId   = item.Id,
                                OrderDate = item.DateCreated.ToString(),
                                Price     = item.Amount.ToString("C", nfi)
                            };
                            newOrders.Add(newItem);
                        }

                        if (string.IsNullOrEmpty(user.Email))
                        {
                            output.IsMember = false;
                        }
                        else
                        {
                            output.IsMember = true;
                        }
                        output.Orders     = newOrders;
                        output.UserEmail  = user.Email;
                        output.UserName   = user.FName + user.LName;
                        output.DateJoined = user.DateCreated.ToString();
                        output.Result     = "OK";
                    }
                    else
                    {
                        output.Result = "CREDENTIAL_ERROR";
                    }
                }
            }

            return(output);
        }
Beispiel #2
0
        public UserInfoOutput CheckUserById([FromBody] UserInfoInput input)
        {
            UserInfoOutput output  = new UserInfoOutput();
            AspUserService aspUser = new AspUserService(_db, this);

            if (aspUser.IsAdmin)
            {
                if (input == null)
                {
                    Response.StatusCode = 400;
                    output.Result       = "INPUT_IS_NULL";
                }
                else
                {
                    BCPUser user = _db._BCPUsers.Where(e => e.Id.Equals(input.UserId)).FirstOrDefault();
                    if (user == null)
                    {
                        Response.StatusCode = 400;
                        output.Result       = "USER_NOT_EXIST";
                    }
                    else
                    {
                        output.Email  = user.Email;
                        output.Name   = user.Name;
                        output.Result = "OK";
                    }
                }
            }
            else
            {
                Response.StatusCode = 400;
                output.Result       = "NO_PRIVILEGE";
            }
            return(output);
        }
        public async Task <IActionResult> Create([Bind("Id,Fname,Lname,Startweight,Currentweight,Desiredweight,Feet,Inches,Sex,Activitylevel,Lastloggedin,Birthday")] UserInfoInput userinfoinput)
        {
            byte     height   = (byte)((userinfoinput.Feet * 12) + userinfoinput.Inches);
            Userinfo userinfo = new Userinfo(userinfoinput.Id, userinfoinput.Fname, userinfoinput.Lname, userinfoinput.Startweight, userinfoinput.Startweight, userinfoinput.Desiredweight, height, userinfoinput.Sex, userinfoinput.Activitylevel, userinfoinput.Birthday);

            userinfo.Lastloggedin = DateTime.Now;
            if (ModelState.IsValid)
            {
                _context.Add(userinfo);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Profile)));
            }
            ViewBag.userID = userinfoinput.Id;
            return(View(userinfoinput));
            /*Replacing below code*/

            /*
             * if (ModelState.IsValid)
             * {
             *  _context.Add(userinfo);
             *  await _context.SaveChangesAsync();
             *  return RedirectToAction(nameof(Index));
             * }
             * ViewData["Id"] = new SelectList(_context.AspNetUsers, "Id", "Id", userinfo.Id);
             * return View(userinfo);
             */
        }
        public async Task <JsonResult> SeetingUserInfo(UserInfoInput model)
        {
            var ajaxResponse = await _userInfoAppService.SeetingUserInfo(model);

            return(Json(ajaxResponse));
            //return Json(true);
        }
Beispiel #5
0
        public async Task <IActionResult> GetCurrentUesrInfo()
        {
            var request = new UserInfoInput();

            request.UserId = (await _currentUserProvider.GetCurrentUser()).Id;
            return(await _dispatcher.DispatchAsync(request));
        }
Beispiel #6
0
 /// <summary>
 /// 根据邮箱获取用户
 /// </summary>
 /// <param name="input"></param>
 /// <returns></returns>
 public async Task<UserInfoOutput> GetUserInfoByEmail(UserInfoInput input)
 {
     var userInfos = await this._userInfoRepository.GetAllListAsync(w => w.Email == input.Email);
     return new UserInfoOutput
     {
         UserInfo = userInfos.FirstOrDefault().MapTo<UserInfoDto>()
     };
 }
Beispiel #7
0
        public async Task <string> CreateUser(UserInfoInput user)
        {
            ValidationResult validationResult = _userInfoInputValidator.Validate(user);

            if (!validationResult.IsValid)
            {
                throw new LotteryDataException(validationResult.Errors.Select(p => p.ErrorMessage).ToList().ToString(";"));
            }

            var validIdentifyCodeOutput = _identifyCodeAppService.ValidIdentifyCode(user.Account, user.IdentifyCode);

            if (validIdentifyCodeOutput.IsOvertime)
            {
                await SendCommandAsync(new InvalidIdentifyCodeCommand(validIdentifyCodeOutput.IdentifyCodeId, user.Account, "system"));

                throw new LotteryDataException("验证码超时,请重新获取验证码");
            }
            if (!validIdentifyCodeOutput.IsValid)
            {
                // await SendCommandAsync(new InvalidIdentifyCodeCommand(validIdentifyCodeOutput.IdentifyCodeId, user.Account, _lotterySession.UserId));
                throw new LotteryDataException("您输入的验证码错误,请重新输入");
            }

            var accountRegType = AccountHelper.JudgeAccountRegType(user.Account);
            var isReg          = await _userManager.IsExistAccount(user.Account);

            if (isReg)
            {
                await SendCommandAsync(new InvalidIdentifyCodeCommand(validIdentifyCodeOutput.IdentifyCodeId, user.Account, "system"));

                throw new LotteryDataException("该账号已经存在");
            }

            var userId = Guid.NewGuid().ToString();

            var userInfoCommand = new AddUserInfoCommand(userId, user.Account,
                                                         EncryptPassword(user.Account, user.Password, accountRegType),
                                                         user.ClientRegistType, accountRegType, 0);
            var commandResult = await SendCommandAsync(userInfoCommand);

            var signedPointInfo = _pointQueryService.GetPointInfoByType(PointType.Register);
            var sinedNotes      = $"{DateTime.Now.ToString("yyyy-MM-dd")}日,注册即送积分";

            await SendCommandAsync(new AddPointRecordCommand(Guid.NewGuid().ToString(), signedPointInfo.Point,
                                                             PointType.Signed, PointOperationType.Increase, sinedNotes, userId));

            if (commandResult.Status != AsyncTaskStatus.Success)
            {
                throw new LotteryDataException("创建用户失败");
            }
            await SendCommandAsync(new InvalidIdentifyCodeCommand(validIdentifyCodeOutput.IdentifyCodeId, user.Account,
                                                                  user.Account));

            return("注册用户成功");
        }
Beispiel #8
0
        public async Task <bool> Add(UserInfoInput addInput)
        {
            WebCoreUser entity = mapper.Map <WebCoreUser>(addInput);

            entity.CreatedBy    = GetCurrentUserLogin();
            entity.CreatedDate  = DateTime.Now;
            entity.ModifiedBy   = entity.CreatedBy;
            entity.ModifiedDate = entity.CreatedDate;
            entity.UpdateToken  = Guid.NewGuid();

            IdentityResult result = await userManager.CreateAsync(entity);

            return(result.Succeeded);
        }
Beispiel #9
0
        public IActionResult InputInfoPartial(EntityId <string> idModel = null)
        {
            UserInfoInput input = null;

            if (idModel == null)
            {
                input = new UserInfoInput();
            }
            else
            {
                input = userService.GetInputById(idModel);
            }

            return(PartialView(input));
        }
Beispiel #10
0
        public UserInfoInput GetInputById(EntityId <string> entityId)
        {
            WebCoreUser entity = userRepository.GetById(entityId.Id);

            UserInfoInput updateInput = new UserInfoInput();

            if (entity == null)
            {
                return(null);
            }

            updateInput = mapper.Map <UserInfoInput>(entity);

            return(updateInput);
        }
Beispiel #11
0
        public async Task <IActionResult> InputInfoPartial(UserInfoInput inputModel)
        {
            if (inputModel.Id != null)
            {
                //update
                WebCoreUser lastInfo = userService.GetById(inputModel);
                if (lastInfo.UpdateToken.GetValueOrDefault(Guid.Empty).Equals(inputModel.UpdateToken))
                {
                    await userService.UpdateInfo(inputModel);

                    return(Ok(new { result = ConstantConfig.WebApiStatusCode.Success, message = GetLang(ConstantConfig.WebApiResultMessage.UpdateSuccess) }));
                }
                return(Ok(new { result = ConstantConfig.WebApiStatusCode.Warning, message = GetLang(ConstantConfig.WebApiResultMessage.UpdateTokenNotMatch) }));
            }
            return(Ok(new { result = ConstantConfig.WebApiStatusCode.Error, message = GetLang(ConstantConfig.WebApiResultMessage.Error) }));
        }
Beispiel #12
0
        public UserInfoOutput AddByEmail([FromBody] UserInfoInput input)
        {
            AspUserService aspUser = new AspUserService(_db, this);
            UserInfoOutput output  = new UserInfoOutput();

            if (aspUser.IsAdmin)
            {
                BCPUser user = _db._BCPUsers.Where(e => e.Email.ToUpper().Equals(input.Email.ToUpper()) && e.Deleted == false).FirstOrDefault();
                if (user == null)
                {
                    Response.StatusCode = 400;
                    output.Result       = "USER_NOT_EXIST";
                }
                else
                {
                    if (user.Status == 2 || user.Status == 4)
                    {
                        Response.StatusCode = 400;
                        output.Result       = "USER_ALREADY_ASSIGNED_LECTURER";
                    }
                    else
                    {
                        if (user.Status == 3)
                        {
                            user.Status = 4;
                        }
                        else
                        {
                            user.Status = 2;
                        }
                        _db.SaveChanges();

                        output.Result = "OK";
                    }
                }
            }
            else
            {
                Response.StatusCode = 400;
                output.Result       = "NO_PRIVILEGE";
            }


            return(output);
        }
Beispiel #13
0
        public CommonRtn getMyInfo([FromForm] UserInfoInput input)
        {
            var instance = this.userService.decodeToken(this.commonService.getAuthenticationHeader());

            // if (instance.user.mechineId == input.mechineId)
            // {
            var dbUser = (from user in this.sysContext.users where user.id == instance.user.id select user)
                         .Include(u => u.company)
                         .Include(u => u.post)
                         .Include(u => u.companyFramework)
                         .FirstOrDefault();

            return(new CommonRtn {
                success = true, message = "", resData = new Dictionary <string, object> {
                    { "user", dbUser }
                }
            });
        }
Beispiel #14
0
        public CommonRtn getUserInfo([FromBody] UserInfoInput input)
        {
            var user = this.userService.decodeToken(input.token);

            if (user.user.mechineId == input.mechineId)
            {
                return(new CommonRtn {
                    success = true, message = "", resData = new Dictionary <string, object> {
                        { "user", user.user }
                    }
                });
            }
            else
            {
                return(new CommonRtn {
                    success = true, message = "设备不一致"
                });
            }
        }
Beispiel #15
0
        public async Task <IActionResult> UpdateInfo(UserInfoInput updateInput)
        {
            if (!ModelState.IsValid)
            {
                string errorLangCode = ConstantConfig.WebApiResultMessage.Error;
                string errorMessage  = languageService.GetlangByKey(errorLangCode);
                return(BadRequest(new
                {
                    Message = errorMessage,
                    ModelErrors = GetModelErrors()
                }));
            }

            Entities.WebCoreUser lastEntity = userService.GetById(updateInput);

            if (lastEntity == null)
            {
                return(NotFound());
            }

            // check update token
            if (!lastEntity.UpdateToken.GetValueOrDefault().Equals(updateInput.UpdateToken))
            {
                string errorLangCode = ConstantConfig.WebApiResultMessage.UpdateTokenNotMatch;
                string errorMessage  = languageService.GetlangByKey(errorLangCode);
                return(BadRequest(new
                {
                    StatusCode = ConstantConfig.WebApiStatusCode.Warning,
                    Message = errorMessage
                }));
            }

            bool result = await userService.UpdateInfo(updateInput);

            if (!result)
            {
                string errorLangCode = ConstantConfig.WebApiResultMessage.Error;
                string errorMessage  = languageService.GetlangByKey(errorLangCode);
                return(BadRequest(errorMessage));
            }

            return(Ok(updateInput));
        }
Beispiel #16
0
        public UserInfoOutput Remove([FromBody] UserInfoInput input)
        {
            UserInfoOutput output  = new UserInfoOutput();
            AspUserService aspUser = new AspUserService(_db, this);

            if (aspUser.IsAdmin)
            {
                if (input == null)
                {
                    Response.StatusCode = 400;
                    output.Result       = "INPUT_IS_NULL";
                }
                else
                {
                    BCPUser user = _db._BCPUsers.Where(e => e.Id.Equals(input.UserId)).FirstOrDefault();
                    if (user == null)
                    {
                        Response.StatusCode = 400;
                        output.Result       = "USER_NOT_EXIST";
                    }
                    else
                    {
                        if (user.Status == 4)
                        {
                            user.Status = 3;
                        }
                        else
                        {
                            user.Status = 1;
                        }

                        _db.SaveChanges();
                        output.Result = "OK";
                    }
                }
            }
            else
            {
                Response.StatusCode = 400;
                output.Result       = "NO_PRIVILEGE";
            }
            return(output);
        }
Beispiel #17
0
        public async Task <UserInfoOutput> WebLogin([FromBody] UserInfoInput input)
        {
            UserInfoOutput output = new UserInfoOutput();

            if (input == null)
            {
                Response.StatusCode = 400;
                output.Result       = "INPUT_IS_NULL";
            }
            else
            {
                if (string.IsNullOrEmpty(input.Email) || string.IsNullOrEmpty(input.Password))
                {
                    Response.StatusCode = 400;
                    output.Result       = "INPUT_IS_NULL";
                }
                else
                {
                    IdentityUser aspUser = _db._AspNetUsers.Where(e => e.UserName.ToLower().Equals(input.Email.ToLower())).FirstOrDefault();
                    if (aspUser == null)
                    {
                        Response.StatusCode = 400;
                        output.Result       = "USER_NOT_FOUND";
                    }
                    else
                    {
                        if (_userManager.PasswordHasher.VerifyHashedPassword(aspUser, aspUser.PasswordHash, input.Password) == PasswordVerificationResult.Success)
                        {
                            await _signInManager.SignInAsync(aspUser, true);

                            output.Result = "OK";
                        }
                        else
                        {
                            Response.StatusCode = 400;
                            output.Result       = "PASSWORD_MISMATCH";
                        }
                    }
                }
            }
            return(output);
        }
Beispiel #18
0
        public async Task <bool> UpdateInfo(UserInfoInput updateInput)
        {
            WebCoreUser entity = userRepository.GetById(updateInput.Id);

            if (entity == null)
            {
                return(false);
            }

            mapper.Map(updateInput, entity);

            entity.RecordStatus = ConstantConfig.UserRecordStatus.Active;

            entity.ModifiedBy   = GetCurrentUserLogin();
            entity.ModifiedDate = DateTime.Now;
            entity.UpdateToken  = Guid.NewGuid();
            IdentityResult result = await userManager.UpdateAsync(entity);

            return(result.Succeeded);
        }
        public async Task <IActionResult> Edit(string id, [Bind("Id,Fname,Lname,Startweight,Currentweight,Desiredweight,Feet,Inches,Sex,Activitylevel,Lastloggedin,Birthday")] UserInfoInput userinfo)
        {
            if (id != userinfo.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                if (!userinfo.Currentweight.HasValue)
                {
                    userinfo.Currentweight = userinfo.Startweight;
                }
                byte     height  = (byte)((userinfo.Feet * 12) + userinfo.Inches);
                Userinfo theUser = new Userinfo(userinfo.Id, userinfo.Fname, userinfo.Lname, userinfo.Startweight, userinfo.Currentweight, userinfo.Desiredweight, height, userinfo.Sex, userinfo.Activitylevel, DateTime.Now, userinfo.Birthday);
                try
                {
                    _context.Update(theUser);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserinfoExists(userinfo.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Profile)));
            }
            //ViewData["Id"] = new SelectList(_context.AspNetUsers, "Id", "Id", userinfo.Id);
            return(View(userinfo));
        }
        // GET: Userinfoes/Edit/5
        public async Task <IActionResult> Edit(string id)
        {
            UserInfoInput theUser;

            if (id == null)
            {
                return(NotFound());
            }

            var userinfo = await _context.Userinfo.FindAsync(id);

            if (userinfo == null)
            {
                return(NotFound());
            }

            byte feet   = (byte)(userinfo.Height / 12);
            byte inches = (byte)(userinfo.Height % 12);

            theUser = new UserInfoInput(userinfo.Id, userinfo.Fname, userinfo.Lname, userinfo.Startweight, userinfo.Currentweight, userinfo.Desiredweight, feet, inches, userinfo.Sex, userinfo.Activitylevel, userinfo.Birthday);

            //ViewData["Id"] = new SelectList(_context.AspNetUsers, "Id", "Id", userinfo.Id);
            return(View(theUser));
        }
Beispiel #21
0
        public async Task <IActionResult> Add(UserInfoInput addInput)
        {
            if (!ModelState.IsValid)
            {
                string errorLangCode = ConstantConfig.WebApiResultMessage.Error;
                string errorMessage  = languageService.GetlangByKey(errorLangCode);
                return(BadRequest(new
                {
                    Message = errorMessage,
                    ModelErrors = GetModelErrors()
                }));
            }

            bool result = await userService.Add(addInput);

            if (!result)
            {
                string errorLangCode = ConstantConfig.WebApiResultMessage.Error;
                string errorMessage  = languageService.GetlangByKey(errorLangCode);
                return(BadRequest(errorMessage));
            }

            return(Ok(addInput));
        }
        public async Task UpdateAsyncTest()
        {
            //清空
            var repository = _serviceProvider.GetRequiredService <IUserinfoRepository>();
            await repository.ExecuteSqlRawAsync($"delete from {nameof(userinfo_us)} where 1=1");

            //创建
            var api   = WorkUrl(nameof(UserInfoController), nameof(UserInfoController.CreateAsync));
            var input = new UserInfoInput
            {
                Name = "wyll",
                Age  = 56,
                Sex  = "女"
            };
            var res = await _client.PostAsync(api, CreateHttpContent(input));

            if (!res.IsSuccessStatusCode)
            {
                Assert.Fail();
            }
            var json = await res.Content.ReadAsStringAsync();

            var keyvalue = JSONDeserialize <KeyOutput <int> >(json).KeyValue;

            //查询
            api = WorkUrl(nameof(UserInfoController), nameof(UserInfoController.SingleAsync), keyvalue);
            res = await _client.GetAsync(api);

            if (!res.IsSuccessStatusCode)
            {
                Assert.Fail();
            }
            json = await res.Content.ReadAsStringAsync();

            var output = JSONDeserialize <v_userinfo>(json);

            Assert.IsNotNull(output);
            //修改
            api = WorkUrl(nameof(UserInfoController), nameof(UserInfoController.UpdateAsync), keyvalue, output.timestamp.ToBase64());
            var updinput = new UserInfoUpdInput
            {
                Age = 21,
                Sex = "男"
            };

            res = await _client.PutAsync(api, CreateHttpContent(updinput));

            if (!res.IsSuccessStatusCode)
            {
                Assert.Fail();
            }
            //验证修改
            api = WorkUrl(nameof(UserInfoController), nameof(UserInfoController.SingleAsync), keyvalue);
            res = await _client.GetAsync(api);

            if (!res.IsSuccessStatusCode)
            {
                Assert.Fail();
            }
            json = await res.Content.ReadAsStringAsync();

            output = JSONDeserialize <v_userinfo>(json);
            Assert.IsNotNull(output);
            Assert.AreEqual(output.age, updinput.Age);
            Assert.AreEqual(output.sex, updinput.Sex);
            //删除
            api = WorkUrl(nameof(UserInfoController), nameof(UserInfoController.DeleteAsync), keyvalue, output.timestamp.ToBase64());
            res = await _client.DeleteAsync(api);

            if (!res.IsSuccessStatusCode)
            {
                Assert.Fail();
            }
        }
Beispiel #23
0
        public async Task <KeyOutput <int> > CreateAsync([FromBody] UserInfoInput input)
        {
            var keyvalue = await _userinfoService.CreateAsync(input);

            return(new KeyOutput <int>(keyvalue));
        }
Beispiel #24
0
        public async Task <UserInfoOutput> Create([FromBody] UserInfoInput input)
        {
            UserInfoOutput output = new UserInfoOutput();

            if (input == null)
            {
                Response.StatusCode = 400;
                output.Result       = "INPUT_IS_NULL";
            }
            else
            {
                if (string.IsNullOrEmpty(input.Email) || string.IsNullOrEmpty(input.Password) || string.IsNullOrEmpty(input.ConfirmPassword))
                {
                    Response.StatusCode = 400;
                    output.Result       = "INPUT_IS_NULL";
                }
                else
                {
                    if (input.Password.Length < 6)
                    {
                        Response.StatusCode = 400;
                        output.Result       = "PASSWORD_LENGTH_LESS_6";
                    }
                    else
                    {
                        if (input.Password.Equals(input.ConfirmPassword))
                        {
                            BCPUser user = _db._BCPUsers.Where(e => e.Email.Equals(input.Email)).FirstOrDefault();

                            if (user == null)
                            {
                                IdentityUser newAspUser = new IdentityUser()
                                {
                                    UserName = input.Email,
                                    Email    = input.Email
                                };

                                var status = await _userManager.CreateAsync(newAspUser, input.Password);

                                if (status.Succeeded)
                                {
                                    user = new BCPUser()
                                    {
                                        AspUser = newAspUser,
                                        Name    = input.Name,
                                        Email   = input.Email
                                    };

                                    _db._BCPUsers.Add(user);
                                    _db.SaveChanges();

                                    output.Result = "OK";
                                }
                                else
                                {
                                    Response.StatusCode = 500;
                                    output.Result       = "INTERNAL_ERROR";
                                }
                            }
                            else
                            {
                                Response.StatusCode = 400;
                                output.Result       = "USER_ALREADY_EXIST";
                            }
                        }
                        else
                        {
                            Response.StatusCode = 400;
                            output.Result       = "PASSWORD_MISMATCH";
                        }
                    }
                }
            }
            return(output);
        }