コード例 #1
0
        public IActionResult Add(Findeks findeks)
        {
            var result = _findeksService.Add(findeks);

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }
コード例 #2
0
ファイル: UserManager.cs プロジェクト: Davutb54/RentACar
        public IResult UpdateUserDetails(UserDetailForUpdateDto userDetailForUpdate)
        {
            var user = GetById(userDetailForUpdate.Id).Data;

            if (!HashingHelper.VerifyPasswordHash(userDetailForUpdate.CurrentPassword, user.PasswordHash, user.PasswordSalt))
            {
                return(new ErrorResult());
            }

            user.FirstName = userDetailForUpdate.FirstName;
            user.LastName  = userDetailForUpdate.LastName;
            if (!string.IsNullOrEmpty(userDetailForUpdate.NewPassword))
            {
                byte[] passwordHash, passwordSalt;
                HashingHelper.CreatePasswordHash(userDetailForUpdate.NewPassword, out passwordHash, out passwordSalt);
                user.PasswordHash = passwordHash;
                user.PasswordSalt = passwordSalt;
            }

            _userDal.Update(user);

            var customer = _customerDal.Get(c => c.Id == userDetailForUpdate.CustomerId);

            customer.CompanyName = userDetailForUpdate.CompanyName;

            _customerDal.Update(customer);

            if (!string.IsNullOrEmpty(userDetailForUpdate.NationalIdentity))
            {
                var findeks = _findeksService.GetByCustomerId(userDetailForUpdate.CustomerId).Data;
                if (findeks == null)
                {
                    var newFindeks = new Findeks
                    {
                        CustomerId       = userDetailForUpdate.CustomerId,
                        NationalIdentity = userDetailForUpdate.NationalIdentity
                    };

                    _findeksService.Add(newFindeks);
                }
                else
                {
                    findeks.NationalIdentity = userDetailForUpdate.NationalIdentity;
                    var newFindeks = _findeksService.CalculateFindeksScore(findeks).Data;

                    _findeksDal.Update(newFindeks);
                }
            }

            return(new SuccessResult());
        }