コード例 #1
0
        public async Task BadRequest_When_Called_Put_Without_Email()
        {
            await Should_Delete_All_Registers();

            var model = new CustomerUpdateViewModel
            {
                Id      = await When_Called_Post_Should_Be_Created(),
                Name    = "Customer 2",
                Version = 1
            };

            _customerController.ModelState.AddModelError("Email", "required");
            var result = await _customerController.Put(model);

            Assert.True(result is BadRequestObjectResult);
            var badRequestResult = (BadRequestObjectResult)result;

            Assert.True(badRequestResult.Value is ErrorResponseDto);

            var resultModel = (ErrorResponseDto)badRequestResult.Value;

            Assert.Single(resultModel.Errors);
            Assert.Contains(resultModel.Errors, a => a.Field == "Email");
            Assert.Contains(resultModel.Errors, a => a.Messages.All(all => all.ToLower().Contains("required")));
        }
コード例 #2
0
        public async Task <IActionResult> Update(CustomerUpdateViewModel model)
        {
            try
            {
                var customer = new CustomerUpdateDTO
                {
                    CusId       = model.CusId,
                    FullName    = model.FullName,
                    Address     = model.Address,
                    PhoneNumber = model.PhoneNumber,
                    Gender      = model.Gender,
                    Email       = model.Email
                };


                await _customerService.Update(customer).ConfigureAwait(true);

                _toastNotification.AddSuccessToastMessage("Updated to :- " + customer.FullName);
            }
            catch (Exception ex)
            {
                _toastNotification.AddErrorToastMessage(ex.Message);
            }

            return(RedirectToAction("Index"));
        }
コード例 #3
0
        [HttpPut("{id}")] //  ./api/customers/:id
        public IActionResult Update(int id, [FromBody] CustomerUpdateViewModel model)
        {
            if (model == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(new ValidationFailedResult(ModelState));
            }

            var customer = _customerData.Get(id);

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

            //update only editable properties from model
            customer.EmailAddress           = model.EmailAddress;
            customer.FirstName              = model.FirstName;
            customer.LastName               = model.LastName;
            customer.PhoneNumber            = model.PhoneNumber;
            customer.PreferredContactMethod = model.PreferredContactMethod;

            _customerData.Update(customer);
            _customerData.Commit();
            return(Ok(new CustomerDisplayViewModel(customer))); //server version, updated per request
        }
コード例 #4
0
        public IActionResult Update(CustomerUpdateViewModel vm)
        {
            string userId = _userManager.GetUserId(User);

            //check if data is valid
            if (ModelState.IsValid)
            {
                Customer customer = _customerService.GetSingle(c => c.UserID == userId);


                customer.FirstName   = vm.FirstName;
                customer.LastName    = vm.LastName;
                customer.DOB         = vm.DOB;
                customer.PhoneNumber = vm.PhoneNumber;
                customer.UserID      = userId;



                //call service
                _customerService.Update(customer);


                //return to page
                return(RedirectToAction("Profile", "Customer"));
            }

            //if invalid
            return(View(vm));
        }
コード例 #5
0
        [HttpPut("{id}")] //  ./api/customers/:id
        public IActionResult Update(int id, [FromBody] CustomerUpdateViewModel model)
        {
            var customer = _customerData.Get(id);

            if (customer == null)
            {
                _logger.LogWarning("Customer {0} not found", id);
                return(NotFound());
            }
            string ifMatch = Request.Headers["If-Match"];

            if (ifMatch != customer.LastContactDate.ToString())
            {
                _logger.LogInformation("Customer update failed due to concurrency issue: {0}", id);
                return(StatusCode(422, "Customer has been changed by another user since it was loaded. Reload and try again."));
            }

            // TODO: ensure User owns this customer record, else return 403.

            //update only editable properties from model
            customer.EmailAddress           = model.EmailAddress;
            customer.FirstName              = model.FirstName;
            customer.LastName               = model.LastName;
            customer.PhoneNumber            = model.PhoneNumber;
            customer.PreferredContactMethod = model.PreferredContactMethod;
            customer.LastContactDate        = DateTime.UtcNow; // acting as a last date updated

            _customerData.Update(customer);
            _customerData.Commit();
            return(Ok(customer)); //server version, updated per request
        }
コード例 #6
0
        public async Task <ActionResult> Update(CustomerUpdateViewModel model)
        {
            try
            {
                var CustomerDto = new CustomerUpdateDTO
                {
                    CusId       = model.CusId,
                    FullName    = model.FullName,
                    Address     = model.Address,
                    PhoneNumber = model.PhoneNumber,
                    Gender      = model.Gender,
                    Email       = model.Email
                };

                await _customerService.Update(CustomerDto).ConfigureAwait(true);

                var Customer = await _customerRepo.GetByNumber(CustomerDto.PhoneNumber) ?? throw new CustomerNotFoundException();

                return(Ok(CreateReponseDto(Customer)));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
コード例 #7
0
 private static void BrainLessUSChangeMemberInfo(CustomerUpdateViewModel profileModel, int brainLessUserId)
 {
     if (brainLessUserId > 0)
     {
         BrainlessClient brainLessClient = new Brainless.BrainlessClient();
         brainLessClient.UpdateUser(brainLessUserId, profileModel);
     }
 }
コード例 #8
0
ファイル: MappingsTests.cs プロジェクト: aubie87/AdWorksCore3
        public void MapCustomerUpdateViewModelToCustomer_ShouldBeValid()
        {
            CustomerUpdateViewModel vm = new CustomerUpdateViewModel
            {
                FirstName = "Zelda",
                LastName  = "Zucker"
            };

            Customer customer = mapper.Map <Customer>(vm);

            Assert.IsType <Customer>(customer);
            Assert.Equal(vm.FirstName, customer.FirstName);
        }
コード例 #9
0
        public async Task <IActionResult> Update([FromBody] CustomerUpdateViewModel vm, int id)
        {
            Customer customer = await repository.GetByIdAsync(id);

            if (customer == null)
            {
                // should PUT create the resource or error out?
                return(NotFound());
            }

            mapper.Map(vm, customer);
            await repository.UpdateAsync(customer);

            return(NoContent());
        }
コード例 #10
0
        private void UmbracoChangePassword(CustomerUpdateViewModel profileModel, Umbraco.Core.Models.IPublishedContent user)
        {
            if (profileModel.ConfirmPassword == profileModel.Password && !string.IsNullOrWhiteSpace(profileModel.Password))
            {
                var result = Members.ChangePassword(user.Name, new Umbraco.Web.Models.ChangingPasswordModel()
                {
                    NewPassword = profileModel.Password,
                    OldPassword = profileModel.CurrentPassword,
                    Reset       = false
                }, UMBRACOMEMBERSHIPPROVIDER);

                if (!result.Success)
                {
                    throw new Exception(string.Format("Forkert nuværende adgangskode. Prøv igen (Fejlkode: {0})", result.Result.ChangeError.ErrorMessage));
                }
            }
        }
コード例 #11
0
        public async Task <ActionResult <CustomerGetViewModel> > Create([FromBody] CustomerUpdateViewModel updateVm)
        {
            Customer customer = mapper.Map <Customer>(updateVm);

            customer = PasswordService.GenerateNewHash(customer, customer.FirstName + customer.LastName);
            try
            {
                customer = await repository.AddAsync(customer);

                CustomerGetViewModel getVm = mapper.Map <CustomerGetViewModel>(customer);
                return(CreatedAtAction(nameof(GetById), new { id = getVm.Id }, getVm));
            }
            catch (Exception e)
            {
                logger.LogError(e, "Saving changes for new customer failed.");
            }
            return(BadRequest());
        }
コード例 #12
0
        public IActionResult Update(int id)
        {
            var user = User.Identity.Name;

            string   userId            = _userManager.GetUserId(User);
            Customer cust              = _customerService.GetSingle(c => c.UserID == userId);
            CustomerUpdateViewModel vm = new CustomerUpdateViewModel
            {
                CustomerId  = cust.CustomerId,
                FirstName   = cust.FirstName,
                LastName    = cust.LastName,
                Email       = user,
                DOB         = cust.DOB,
                PhoneNumber = cust.PhoneNumber
            };

            return(View(vm));
        }
コード例 #13
0
        public async Task Ok_When_Called_Put()
        {
            await Should_Delete_All_Registers();

            var model = new CustomerUpdateViewModel
            {
                Id      = await When_Called_Post_Should_Be_Created(),
                Email   = "*****@*****.**",
                Name    = "Customer 2",
                Version = 1
            };

            var result = await _customerController.Put(model);

            var response = (ObjectResult)result;

            Assert.True(response.Value != null);
            Assert.True(response.StatusCode.Equals(200));
        }
コード例 #14
0
        [HttpPut("{id}")] //  ./api/customers/:id
        public IActionResult Update(int id, [FromBody] CustomerUpdateViewModel model)
        {
            if (model == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {   //rules failed, return a well formed error
                _logger.LogWarning("Customer Update failed due to validation");
                return(new ValidationFailedResult(ModelState));
            }

            var customer = _customerData.Get(id);

            if (customer == null)
            {
                _logger.LogWarning("Customer {0} not found", id);
                return(NotFound());
            }

            string ifMatch = Request.Headers["If-Match"];

            if (ifMatch != customer.LastContactDate.ToString())
            {
                _logger.LogInformation("Customer update failed due to concurrency issue: {0}", id);
                return(StatusCode(422, "This record has been updated by another user. Please refresh and try again."));
            }

            //update only editable properties from model
            customer.EmailAddress           = model.EmailAddress;
            customer.FirstName              = model.FirstName;
            customer.LastName               = model.LastName;
            customer.PhoneNumber            = model.PhoneNumber;
            customer.PreferredContactMethod = model.PreferredContactMethod;
            customer.LastContactDate        = DateTime.UtcNow;

            _customerData.Update(customer);
            _customerData.Commit();
            return(Ok(customer)); //server version, updated per request
        }
コード例 #15
0
        public async Task ForCustomer_Create_ValidCustomer()
        {
            // Arrange
            int      newId          = 101;
            Customer retCustomer    = GetTestCustomer(newId);
            var      mockLogger     = new Mock <ILogger <CustomersController> >();
            var      mockRepository = new Mock <ICustomerRepository>();

            // Tell Moq to match on any customer instance
            mockRepository.Setup(repo => repo.AddAsync(It.IsAny <Customer>()))
            .ReturnsAsync(retCustomer);
            var controller = new CustomersController(mockLogger.Object, mapper, mockRepository.Object);

            // Act
            var result = await controller.Create(CustomerUpdateViewModel.FromCustomerEntity(GetTestUpdate()));

            // Assert
            var apiResult = Assert.IsType <CreatedAtActionResult>(result.Result);
            var model     = Assert.IsAssignableFrom <CustomerGetViewModel>(apiResult.Value);

            Assert.Equal(newId, model.Id);
        }
コード例 #16
0
ファイル: MappingsTests.cs プロジェクト: aubie87/AdWorksCore3
        public void MapCustomerUpdateViewModelWithExistingCustomer_ShouldBeUpdated()
        {
            CustomerUpdateViewModel vm = new CustomerUpdateViewModel
            {
                FirstName = "Wan",
                LastName  = "Woon"
            };

            Customer customer = new Customer
            {
                CustomerId   = 23,
                ModifiedDate = DateTime.UtcNow,
                FirstName    = "Hector",
                LastName     = "Herrera"
            };

            mapper.Map(vm, customer);

            Assert.Equal(23, customer.CustomerId);
            Assert.Equal(vm.FirstName, customer.FirstName);
            Assert.Equal(vm.LastName, customer.LastName);
        }
コード例 #17
0
        public async Task <IActionResult> Update(long id)
        {
            try
            {
                var customer = await _customerRepo.GetById(id).ConfigureAwait(true) ?? throw new CustomerNotFoundException("Customer has not been found of that number!");

                var model = new CustomerUpdateViewModel
                {
                    CusId       = customer.CusId,
                    FullName    = customer.FullName,
                    Email       = customer.Email,
                    PhoneNumber = customer.PhoneNumber,
                    Gender      = customer.Gender,
                    Address     = customer.Address
                };

                return(View(model));
            }
            catch (Exception ex)
            {
                _toastNotification.AddErrorToastMessage(ex.Message);
                return(RedirectToAction("Index"));
            }
        }
コード例 #18
0
        public async Task <IHttpActionResult> Updatecustomer()
        {
            ResponseDataDTO <customer> response = new ResponseDataDTO <customer>();

            try
            {
                var path = Path.GetTempPath();

                if (!Request.Content.IsMimeMultipartContent("form-data"))
                {
                    throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.UnsupportedMediaType));
                }

                MultipartFormDataStreamProvider streamProvider = new MultipartFormDataStreamProvider(path);

                await Request.Content.ReadAsMultipartAsync(streamProvider);

                // save file
                string fileName = "";
                if (streamProvider.FileData.Count > 0)
                {
                    foreach (MultipartFileData fileData in streamProvider.FileData)
                    {
                        fileName = FileExtension.SaveFileOnDisk(fileData);
                    }
                }
                //Cach truong bat buoc
                if (streamProvider.FormData["cu_fullname"] == null)
                {
                    response.Code    = HttpCode.INTERNAL_SERVER_ERROR;
                    response.Message = "Họ và tên không được để trống";
                    response.Data    = null;
                    return(Ok(response));
                }
                if (streamProvider.FormData["cu_mobile"] == null)
                {
                    response.Code    = HttpCode.INTERNAL_SERVER_ERROR;
                    response.Message = "Số điện thoại không được để trống";
                    response.Data    = null;
                    return(Ok(response));
                }
                if (streamProvider.FormData["cu_email"] == null)
                {
                    response.Code    = HttpCode.INTERNAL_SERVER_ERROR;
                    response.Message = "Email không được để trống";
                    response.Data    = null;
                    return(Ok(response));
                }
                if (streamProvider.FormData["cu_type"] == null)
                {
                    response.Code    = HttpCode.INTERNAL_SERVER_ERROR;
                    response.Message = "Loại khách hàng không được để trống";
                    response.Data    = null;
                    return(Ok(response));
                }
                if (streamProvider.FormData["customer_group_id"] == null)
                {
                    response.Code    = HttpCode.INTERNAL_SERVER_ERROR;
                    response.Message = "Nhóm khách hàng không được để trống";
                    response.Data    = null;
                    return(Ok(response));
                }
                if (streamProvider.FormData["source_id"] == null)
                {
                    response.Code    = HttpCode.INTERNAL_SERVER_ERROR;
                    response.Message = "Nguồn không được để trống";
                    response.Data    = null;
                    return(Ok(response));
                }
                // get data from formdata
                CustomerUpdateViewModel customerUpdateViewModel = new CustomerUpdateViewModel
                {
                    cu_id       = Convert.ToInt32(streamProvider.FormData["cu_id"]),
                    cu_mobile   = Convert.ToString(streamProvider.FormData["cu_mobile"]),
                    cu_email    = Convert.ToString(streamProvider.FormData["cu_email"]),
                    cu_fullname = Convert.ToString(streamProvider.FormData["cu_fullname"]),

                    customer_group_id = Convert.ToInt32(streamProvider.FormData["customer_group_id"]),
                    source_id         = Convert.ToInt32(streamProvider.FormData["source_id"]),

                    cu_type = Convert.ToByte(streamProvider.FormData["cu_type"]),
                };


                var existcustomer = _customerservice.Find(customerUpdateViewModel.cu_id);

                if (streamProvider.FormData["cu_thumbnail"] != null)
                {
                    if (fileName != "")
                    {
                        customerUpdateViewModel.cu_thumbnail = fileName;
                    }
                    else
                    {
                        customerUpdateViewModel.cu_thumbnail = existcustomer.cu_thumbnail;
                    }
                }

                //md5

                if (CheckEmail.IsValidEmail(customerUpdateViewModel.cu_email) == false && customerUpdateViewModel.cu_email == "")
                {
                    response.Message = "Định dạng email không hợp lệ !";
                    response.Data    = null;
                    return(Ok(response));
                }
                //check_phone_number
                if (CheckNumber.IsPhoneNumber(customerUpdateViewModel.cu_mobile) == false && customerUpdateViewModel.cu_mobile == "")
                {
                    response.Message = "Số điện thoại không hợp lệ";
                    response.Data    = null;
                    return(Ok(response));
                }
                //bat cac truog con lai
                if (streamProvider.FormData["cu_birthday"] == null)
                {
                    if (existcustomer.cu_birthday != null)
                    {
                        customerUpdateViewModel.cu_birthday = existcustomer.cu_birthday;
                    }
                    else
                    {
                        customerUpdateViewModel.cu_birthday = null;
                    }
                }
                else
                {
                    customerUpdateViewModel.cu_birthday = Convert.ToDateTime(streamProvider.FormData["cu_birthday"]);
                }
                if (streamProvider.FormData["cu_address"] == null)
                {
                    customerUpdateViewModel.cu_address = null;
                }
                else
                {
                    customerUpdateViewModel.cu_address = Convert.ToString(streamProvider.FormData["cu_address"]);
                }
                if (streamProvider.FormData["cu_note"] == null)
                {
                    customerUpdateViewModel.cu_note = null;
                }
                else
                {
                    customerUpdateViewModel.cu_note = Convert.ToString(streamProvider.FormData["cu_note"]);
                }
                if (streamProvider.FormData["cu_geocoding"] == null)
                {
                    customerUpdateViewModel.cu_geocoding = null;
                }
                else
                {
                    customerUpdateViewModel.cu_geocoding = Convert.ToString(streamProvider.FormData["cu_geocoding"]);
                }
                if (streamProvider.FormData["cu_curator_id"] == null)
                {
                    customerUpdateViewModel.cu_curator_id = null;
                }
                else
                {
                    customerUpdateViewModel.cu_curator_id = Convert.ToInt32(streamProvider.FormData["cu_curator_id"]);
                }
                if (streamProvider.FormData["cu_age"] == null)
                {
                    customerUpdateViewModel.cu_age = null;
                }
                else
                {
                    customerUpdateViewModel.cu_age = Convert.ToInt32(streamProvider.FormData["cu_age"]);
                }


                if (streamProvider.FormData["cu_status"] == null)
                {
                    customerUpdateViewModel.cu_status = null;
                }
                else
                {
                    customerUpdateViewModel.cu_status = Convert.ToByte(streamProvider.FormData["cu_status"]);
                }

                // mapping view model to entity
                var updatedcustomer = _mapper.Map <customer>(customerUpdateViewModel);



                // update customer
                _customerservice.Update(updatedcustomer, customerUpdateViewModel.cu_id);

                // return response
                response.Code    = HttpCode.OK;
                response.Message = MessageResponse.SUCCESS;
                response.Data    = updatedcustomer;
                return(Ok(response));
            }
            catch (Exception ex)
            {
                response.Code    = HttpCode.INTERNAL_SERVER_ERROR;
                response.Message = ex.Message;
                response.Data    = null;
                Console.WriteLine(ex.ToString());

                return(Ok(response));
            }
        }
コード例 #19
0
        public ActionResult UpdateProfile(CustomerUpdateViewModel profileModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var      user            = Members.GetCurrentMember();
                    int      websitePanelId  = 0;
                    int      economicId      = 0;
                    int      brainLessUserId = 0;
                    DateTime timeNow         = DateTime.Now;

                    if (user.Properties.FirstOrDefault(p => p.PropertyTypeAlias == WEBSITEPANELUSERID) != null && user.GetProperty(WEBSITEPANELUSERID).HasValue)
                    {
                        websitePanelId = (int)user.GetProperty(WEBSITEPANELUSERID).Value;
                    }

                    if (user.Properties.FirstOrDefault(p => p.PropertyTypeAlias == ECONOMICID) != null && user.GetProperty(ECONOMICID).HasValue)
                    {
                        economicId = (int)user.GetProperty(ECONOMICID).Value;
                    }

                    if (user.Properties.FirstOrDefault(p => p.PropertyTypeAlias == BRAINLESSID) != null && user.GetProperty(BRAINLESSID).HasValue)
                    {
                        brainLessUserId = (int)user.GetProperty(BRAINLESSID).Value;
                    }

                    if (Members.GetByEmail(profileModel.Email) != null)
                    {
                        throw new Exception(string.Format("Email {0} er allerede brugt. Kontakts os for nærmere information.", profileModel.Email));
                    }

                    esUsersSoapClient          client     = null;
                    esAuthenticationSoapClient clientAuth = null;

                    if (websitePanelId > 0)
                    {
                        client = new esUsersSoapClient(ESUSERSSOAP);
                        client.ClientCredentials.UserName.UserName = WEBSITEPANEL_USERNAME;
                        client.ClientCredentials.UserName.Password = WEBSITEPANEL_PASSWORD;
                        client.Open();


                        clientAuth = new esAuthenticationSoapClient(ESAUTHENTICATIONSOAP);
                        clientAuth.ClientCredentials.UserName.UserName = WEBSITEPANEL_USERNAME;
                        clientAuth.ClientCredentials.UserName.Password = WEBSITEPANEL_PASSWORD;
                        clientAuth.Open();
                    }

                    WebsitepanelService.UserInfo userInfo = null;
                    if (websitePanelId > 0)
                    {
                        userInfo = client.GetUserById(websitePanelId);
                        if (!string.IsNullOrWhiteSpace(profileModel.Address))
                        {
                            userInfo.Address = profileModel.Address;
                        }
                        if (!string.IsNullOrWhiteSpace(profileModel.City))
                        {
                            userInfo.City = profileModel.City;
                        }
                        if (!string.IsNullOrWhiteSpace(profileModel.FirstName))
                        {
                            userInfo.FirstName = profileModel.FirstName;
                        }
                        if (!string.IsNullOrWhiteSpace(profileModel.LastName))
                        {
                            userInfo.LastName = profileModel.LastName;
                        }
                        if (!string.IsNullOrWhiteSpace(profileModel.Postcode))
                        {
                            userInfo.Zip = profileModel.Postcode;
                        }
                        if (!string.IsNullOrWhiteSpace(profileModel.Email))
                        {
                            userInfo.Email = profileModel.Email;
                        }
                        if (!string.IsNullOrWhiteSpace(profileModel.CompanyName))
                        {
                            userInfo.CompanyName = profileModel.CompanyName;
                        }
                        if (!string.IsNullOrWhiteSpace(profileModel.CVRNumber))
                        {
                            userInfo.Comments = string.Format("CVR: {0}", profileModel.CVRNumber);
                        }
                        if (!string.IsNullOrWhiteSpace(profileModel.Country))
                        {
                            var regex = new System.Text.RegularExpressions.Regex(@"([\w+\s*\.*]+\))");

                            foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
                            {
                                RegionInfo region = new RegionInfo(ci.Name);

                                var    match       = regex.Match(ci.EnglishName);
                                string countryName = match.Value.Length == 0 ? "NA" : match.Value.Substring(0, match.Value.Length - 1);

                                if (countryName == profileModel.Country)
                                {
                                    userInfo.Country = region.TwoLetterISORegionName;
                                    break;
                                }
                            }
                        }

                        userInfo.Changed = timeNow;
                    }

                    // websitepanel update
                    if (websitePanelId > 0)
                    {
                        var updateTask = client.UpdateUserAsync(userInfo);
                        if (profileModel.ConfirmPassword == profileModel.Password && !string.IsNullOrWhiteSpace(profileModel.Password))
                        {
                            if (Members.Login(user.Name, profileModel.CurrentPassword))
                            {
                                client.ChangeUserPassword(websitePanelId, profileModel.Password);
                            }
                            else
                            {
                                throw new Exception("Forkert Nuværende adgangskode. ");
                            }
                        }

                        updateTask.Wait(60000);
                    }

                    if (clientAuth != null)
                    {
                        clientAuth.Close();
                        clientAuth.Abort();
                    }

                    if (client != null)
                    {
                        client.Close();
                        client.Abort();
                    }

                    // economic get customer
                    System.Threading.Tasks.Task            eUpdateCustomerTask = null;
                    System.Threading.Tasks.Task <Customer> eGetCustomerTask    = null;
                    if (economicId > 0)
                    {
                        Customer customer = CustomerClient.GetCustomer(economicId);

                        if (!string.IsNullOrWhiteSpace(profileModel.CompanyName) || !string.IsNullOrWhiteSpace(profileModel.FirstName) || !string.IsNullOrWhiteSpace(profileModel.LastName))
                        {
                            if (!string.IsNullOrWhiteSpace(profileModel.CompanyName))
                            {
                                customer.Name = profileModel.CompanyName;
                            }
                            else
                            {
                                customer.Name = string.Format("{0} {1}", profileModel.FirstName, profileModel.LastName);
                            }
                        }

                        if (!string.IsNullOrWhiteSpace(profileModel.Address))
                        {
                            customer.Address = profileModel.Address;
                        }
                        if (!string.IsNullOrWhiteSpace(profileModel.Email))
                        {
                            customer.Email = profileModel.Email;
                        }
                        if (!string.IsNullOrWhiteSpace(profileModel.City))
                        {
                            customer.City = profileModel.City;
                        }
                        if (!string.IsNullOrWhiteSpace(profileModel.Country))
                        {
                            customer.Country = profileModel.Country;
                            customer.County  = profileModel.Country;
                        }
                        if (!string.IsNullOrWhiteSpace(profileModel.Postcode))
                        {
                            customer.Zip = profileModel.Postcode;
                        }
                        if (!string.IsNullOrWhiteSpace(profileModel.Phone))
                        {
                            customer.TelephoneAndFaxNumber = profileModel.Phone;
                        }
                        if (!string.IsNullOrWhiteSpace(profileModel.CVRNumber))
                        {
                            customer.CorporateIdentificationNumber = profileModel.CVRNumber;
                        }

                        // economic update
                        CustomerClient.UpdateCustomer(economicId, customer);
                    }

                    // brainless update
                    BrainLessUSChangeMemberInfo(profileModel, brainLessUserId);

                    // KimDamDev update
                    UmbracoChangePassword(profileModel, user);

                    TempData["success"] = true;

                    return(RedirectToCurrentUmbracoPage("?success=true"));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError(string.Empty, new Exception(string.Format("{0}", ex.Message)));
                }
            }

            TempData["success"] = false;

            return(CurrentUmbracoPage());
        }
コード例 #20
0
        public void UpdateUser(int userId, CustomerUpdateViewModel customer)
        {
            connection.Open();
            var sql = "UPDATE Users SET ";

            var parameters = string.Empty;

            if (!string.IsNullOrWhiteSpace(customer.FirstName))
            {
                parameters += "firstname=@firstname,";
            }
            if (!string.IsNullOrWhiteSpace(customer.LastName))
            {
                parameters += "lastname=@lastname,";
            }
            if (!string.IsNullOrWhiteSpace(customer.Address))
            {
                parameters += "address=@address,";
            }
            if (!string.IsNullOrWhiteSpace(customer.Postcode))
            {
                parameters += "zip=@postCode,";
            }
            if (!string.IsNullOrWhiteSpace(customer.Phone))
            {
                parameters += "phone=@phone,";
            }
            if (!string.IsNullOrWhiteSpace(customer.City))
            {
                parameters += "city=@city,";
            }
            if (!string.IsNullOrWhiteSpace(customer.Country))
            {
                parameters += "country=@country,";
            }
            if (!string.IsNullOrWhiteSpace(customer.Email))
            {
                parameters += "email=@email,";
            }
            parameters = parameters.Remove(parameters.Length - 1);
            sql       += parameters + " WHERE id=@id";

            MySqlCommand cmd = new MySqlCommand(sql, connection);

            cmd.Parameters.Add(new MySqlParameter("id", userId));
            cmd.Parameters.Add(new MySqlParameter("firstname", customer.FirstName));
            cmd.Parameters.Add(new MySqlParameter("lastname", customer.LastName));
            cmd.Parameters.Add(new MySqlParameter("address", customer.Address));
            cmd.Parameters.Add(new MySqlParameter("postCode", customer.Postcode));
            cmd.Parameters.Add(new MySqlParameter("city", customer.City));
            cmd.Parameters.Add(new MySqlParameter("phone", customer.Phone));
            cmd.Parameters.Add(new MySqlParameter("country", customer.Country));
            cmd.Parameters.Add(new MySqlParameter("email", customer.Email));

            cmd.CommandTimeout = 120;
            cmd.CommandType    = System.Data.CommandType.Text;
            var results = cmd.ExecuteReader();

            while (results.Read())
            {
                string username = results.GetString("user");
            }

            connection.Close();
        }
コード例 #21
0
        public IActionResult Update(int customerId)
        {
            var customer = _customerService.GetById(customerId);

            if (customer != null)
            {
                var model = new CustomerUpdateViewModel();
                model.Id            = customer.Id;
                model.User          = HttpContext.User.Identity.Name.ToString();
                model.TC            = customer.TC;
                model.Name          = customer.Name;
                model.Surname       = customer.Surname;
                model.BirthDate     = customer.BirthDate;
                model.Gender        = customer.Gender;
                model.EMail         = customer.EMail;
                model.Address       = customer.Address;
                model.PhoneNumber   = customer.PhoneNumber;
                model.PhoneNumber2  = customer.PhoneNumber2;
                model.DriverLicence = customer.DriverLicence;
                model.GenderList    = new List <SelectListItem>
                {
                    new SelectListItem {
                        Text = "Male", Value = "M"
                    },
                    new SelectListItem {
                        Text = "Female", Value = "F"
                    },
                };

                model.DriverLicenceList = new List <SelectListItem>
                {
                    new SelectListItem {
                        Text = "M", Value = "M"
                    },
                    new SelectListItem {
                        Text = "A1", Value = "A1"
                    },
                    new SelectListItem {
                        Text = "A2", Value = "A2"
                    },
                    new SelectListItem {
                        Text = "A", Value = "A"
                    },
                    new SelectListItem {
                        Text = "B1", Value = "B1"
                    },
                    new SelectListItem {
                        Text = "B", Value = "B"
                    },
                    new SelectListItem {
                        Text = "BE", Value = "BE"
                    },
                    new SelectListItem {
                        Text = "C1", Value = "C1"
                    },
                    new SelectListItem {
                        Text = "C1E", Value = "C1E"
                    },
                    new SelectListItem {
                        Text = "C", Value = "C"
                    },
                    new SelectListItem {
                        Text = "CE", Value = "CE"
                    },
                    new SelectListItem {
                        Text = "D1", Value = "D1"
                    },
                    new SelectListItem {
                        Text = "D1E", Value = "D1E"
                    },
                    new SelectListItem {
                        Text = "D", Value = "D"
                    },
                    new SelectListItem {
                        Text = "DE", Value = "DE"
                    },
                    new SelectListItem {
                        Text = "F", Value = "F"
                    },
                    new SelectListItem {
                        Text = "G", Value = "G"
                    }
                };

                return(View(model));
            }

            TempData["message"] = "Failed to reach update page !";
            return(RedirectToAction("Index", "Customer"));
        }
コード例 #22
0
 public CustomerUpdatePage(CustomerUpdateViewModel viewModel)
 {
     DataContext = viewModel;
     InitializeComponent();
 }