Example #1
0
        public UserDTO UpdateUser(UserDTO user)
        {
            var tempuser      = GetById(user.Id);
            var dbEntityEntry = _movieStoreDbContext.Attach(tempuser);
            //foreach (var property in dbEntityEntry.OriginalValues.Properties)
            //{
            //    var original = dbEntityEntry.OriginalValues.GetValue<object>(property);
            //    var current = dbEntityEntry.CurrentValues.GetValue<object>(property);
            //    if (original != null && !original.Equals(current))
            //        dbEntityEntry.Property(property.Name).IsModified = true;
            //}
            var properties = user.GetType().GetProperties();

            foreach (var pi in properties)
            {
                if (pi.Name.ToLower() == "id")
                {
                    continue;
                }
                var newValue = user.GetType().GetProperty(pi.Name).GetValue(user);
                var oldValue = typeof(User).GetProperty(pi.Name).GetValue(tempuser);

                if (newValue is null && oldValue is null)
                {
                    continue;
                }
Example #2
0
        public ActionResult CheckUserModel(UserModel viewModel)
        {
            //Checks if the user is valid and has agreed to the terms and validated the captcha
            if (viewModel.Agreement && ModelState.IsValid && ReCaptcha.Validate(ConfigurationManager.AppSettings["ReCaptcha:SecretKey"]))
            {
                UserDTO userDTO = new UserDTO
                {
                    Password     = ComputeHash(viewModel.Password),    //Put Hash of password in the database
                    SecretAnswer = ComputeHash(viewModel.SecretAnswer) //Put Hash of secret answer in the database
                };
                foreach (PropertyInfo property in userDTO.GetType()
                         .GetProperties()
                         .Where(property => property.Name != "ID" && property.Name != "Password" && property.Name != "SecretAnswer"))
                {
                    property.SetValue(userDTO, viewModel.GetType().GetProperty(property.Name).GetValue(viewModel).ToString());
                }

                //Submits the user to the database via the service
                _service.Insert(userDTO);

                return(View());
            }
            //User info was not valid, so the model is stored and you are prompted to create the user
            else
            {
                ViewBag.RecaptchaLastErrors = ReCaptcha.GetLastErrors(HttpContext);

                ViewBag.publicKey = ConfigurationManager.AppSettings["ReCaptcha:SiteKey"];

                TempData["agreement"] = "You have not agreed to our terms and conditions";
                TempData["userModel"] = viewModel;
                return(RedirectToAction("Create"));
            }
        }
Example #3
0
        public void TestUserModelDTO()
        {
            UserModel objUserModel = new UserModel();
            UserDTO   objUserDTO   = new UserDTO();
            int       numberOfPublicPropertiesofUserModel = objUserModel.GetType().GetProperties().Count();
            int       numberOfPublicPropertiesofUserDTO   = objUserDTO.GetType().GetProperties().Count();

            Assert.AreEqual(numberOfPublicPropertiesofUserModel, UserModelPropertyCount, "UserModel properties has been changed");
            Assert.AreEqual(numberOfPublicPropertiesofUserDTO, UserDTOPropertyCount, "UserDTO properties has been changed");
        }
        public void ShouldMapUserToUserDTO()
        {
            //Arrange
            var user        = new User();
            var userDTO     = new UserDTO();
            var userDTOType = userDTO.GetType();

            //Act
            var result = Mapper.Map <UserDTO>(user);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, userDTOType);
        }
        /// <summary>
        /// registerAccount
        /// </summary>
        /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="managedUserVM">managedUserVM</param>
        /// <returns>Task of ApiResponse (ResponseEntity)</returns>
        public async System.Threading.Tasks.Task <ApiResponse <ResponseEntity> > RegisterAccountUsingPOSTAsyncWithHttpInfo(UserDTO managedUserVM)
        {
            // verify the required parameter 'managedUserVM' is set
            if (managedUserVM == null)
            {
                throw new ApiException(400, "Missing required parameter 'managedUserVM' when calling AccountResourceApi->RegisterAccountUsingPOST");
            }

            var    localVarPath         = "/api/register";
            var    localVarPathParams   = new Dictionary <String, String>();
            var    localVarQueryParams  = new List <KeyValuePair <String, String> >();
            var    localVarHeaderParams = new Dictionary <String, String>(Configuration.DefaultHeader);
            var    localVarFormParams   = new Dictionary <String, String>();
            var    localVarFileParams   = new Dictionary <String, FileParameter>();
            Object localVarPostBody     = null;

            // to determine the Content-Type header
            String[] localVarHttpContentTypes = new String[] {
                "application/json"
            };
            String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);

            // to determine the Accept header
            String[] localVarHttpHeaderAccepts = new String[] {
                "application/json",
                "text/plain"
            };
            String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);

            if (localVarHttpHeaderAccept != null)
            {
                localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);
            }

            if (managedUserVM != null && managedUserVM.GetType() != typeof(byte[]))
            {
                localVarPostBody = Configuration.ApiClient.Serialize(managedUserVM); // http body (model) parameter
            }
            else
            {
                localVarPostBody = managedUserVM; // byte array
            }

            // authentication (apiKey) required
            if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("Authorization")))
            {
                localVarHeaderParams["Authorization"] = Configuration.GetApiKeyWithPrefix("Authorization");
            }

            // make the HTTP request
            IRestResponse localVarResponse = (IRestResponse)await Configuration.ApiClient.CallApiAsync(localVarPath,
                                                                                                       Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
                                                                                                       localVarPathParams, localVarHttpContentType);

            int localVarStatusCode = (int)localVarResponse.StatusCode;

            if (ExceptionFactory != null)
            {
                Exception exception = ExceptionFactory("RegisterAccountUsingPOST", localVarResponse);
                if (exception != null)
                {
                    throw exception;
                }
            }

            return(new ApiResponse <ResponseEntity>(localVarStatusCode,
                                                    localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
                                                    (ResponseEntity)Configuration.ApiClient.Deserialize(localVarResponse, typeof(ResponseEntity))));
        }