Exemplo n.º 1
0
        public ActionResult Details(int id)
        {
            var customerEditViewModel = new CustomerEditViewModel(id);

            return(View(customerEditViewModel));

            //if (id == null)
            //{
            //    return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            //}
            //int ID = id ?? 0;
            //var customerEdit = await CustomerInfo.GetCustomerAsync(ID);
            //return View(customerEdit);
        }
        public ViewResult Edit(int id)
        {
            Customer customer = _customerRepository.GetCustomer(id);
            CustomerEditViewModel customerEditViewModel = new CustomerEditViewModel
            {
                Id                = customer.Id,
                Name              = customer.Name,
                Email             = customer.Email,
                Department        = customer.Department,
                existingPhotoPath = customer.PhotoPath
            };

            return(View(customerEditViewModel));
        }
        private Customer ViewModel_to_model(Customer customer, CustomerEditViewModel editModel)
        {
            customer.Lastname      = editModel.Lastname;
            customer.Firstname     = editModel.Firstname;
            customer.Career        = editModel.Career;
            customer.gender        = (Customer.Gender)editModel.gender;
            customer.Age           = editModel.Age;
            customer.Homeaddress   = editModel.Homeaddress;
            customer.Officeaddress = editModel.Officeaddress;
            customer.Telnumber     = editModel.Telnumber;
            customer.Email         = editModel.Email;
            customer.Branch        = editModel.Branch;

            return(customer);
        }
Exemplo n.º 4
0
        // GET: Customers/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Customer customer          = db.Customers.Find(id);
            CustomerEditViewModel cevm = new CustomerEditViewModel();

            cevm.customer = customer;
            if (customer == null)
            {
                return(HttpNotFound());
            }
            return(View(cevm));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Edit(CustomerEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await userManager.FindByIdAsync(model.Id);

                mapper.Map(model, user);
                var result = await userManager.UpdateAsync(user);

                if (result.Succeeded)
                {
                    return(RedirectToAction("Index", "Customer"));
                }
            }
            return(View(model));
        }
Exemplo n.º 6
0
        public ActionResult Edit(int?id, CustomerEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    _customerService.UpdateCustomer(model.Id, model.DateOfBirth, model.FirstName, model.LastName, model.MiddleName, model.Gender, model.PhoneNo, model.StreetAddress, model.PostCode, model.Suburb, model.State);
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex);
                }
            }

            return(View(model));
        }
        private CustomerEditViewModel Model_to_viewModel(Customer customer)
        {
            var editModel = new CustomerEditViewModel();

            editModel.ID            = customer.ID;
            editModel.Lastname      = customer.Lastname;
            editModel.Firstname     = customer.Firstname;
            editModel.Career        = editModel.Career;
            editModel.gender        = (CustomerEditViewModel.Gender)customer.gender;
            editModel.Age           = customer.Age;
            editModel.Homeaddress   = customer.Homeaddress;
            editModel.Officeaddress = customer.Officeaddress;
            editModel.Telnumber     = customer.Telnumber;
            editModel.Email         = customer.Email;
            editModel.Branch        = customer.Branch;

            return(editModel);
        }
Exemplo n.º 8
0
 public ActionResult EditCustomerPartial(CustomerEditViewModel model)
 {
     if (ModelState.IsValid)
     {
         var  repo  = new CustomersRepository();
         bool saved = repo.SaveCustomer(model);
         if (saved)
         {
             bool isGuid = Guid.TryParse(model.CustomerID, out Guid customerId);
             if (isGuid)
             {
                 var modelUpdate = repo.GetCustomer(customerId);
                 return(PartialView(modelUpdate));
             }
         }
     }
     return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
 }
Exemplo n.º 9
0
        /// <summary>
        /// Edit a single Customer
        /// </summary>
        /// <param name="key">Key of the customer to edit</param>
        /// <returns>Edit Customer view</returns>
        public ActionResult Edit(Guid key)
        {
            using (var context = dataContextFactory.CreateByUser())
            {
                var customer = (from x in context.Customers where x.ObjectId == key select x).SingleOrDefault();

                if (customer == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
                }

                var countryQuery = from x in context.Countries select x;

                var viewModel = new CustomerEditViewModel(customer, countryQuery.ToList());

                return(View(viewModel));
            }
        }
Exemplo n.º 10
0
        public ActionResult CustomerPasswordChange(CustomerEditViewModel model, int CustomerId)
        {
            var modelCustomer = _unitOfWork.GetRepo <Customer>().Where(x => x.Id == CustomerId).FirstOrDefault();

            model.Customer = modelCustomer;
            if (ModelState.IsValid)
            {
                modelCustomer.Password = _encryptor.Hash(model.PasswordChangeModel.Password);
                _unitOfWork.GetRepo <Customer>().Update(modelCustomer);
            }
            var isSuccess = _unitOfWork.Commit();

            TempData["IsSuccess"]  = isSuccess;
            TempData["ModelState"] = ModelState;
            TempData["Message"]    = isSuccess ? "Şifre güncelleme işlemi başarılı bir şekilde gerçekleştirildi." : "Şifre güncelleme işlemi gerçekleştirilemedi lütfen tekrar deneyiniz.";

            return(RedirectToAction("Edit", new { id = CustomerId }));
        }
Exemplo n.º 11
0
        public async Task <IActionResult> Edit(CustomerEditViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            await _customerRepository.AddOrUpdate(new Customer()
            {
                Id          = model.Id,
                FirstName   = model.FirstName,
                LastName    = model.LastName,
                PhoneNumber = model.PhoneNumer,
                Email       = model.Email,
                IsAdult     = model.IsAdult
            });

            return(RedirectToAction("Index"));
        }
Exemplo n.º 12
0
        public IActionResult Edit()
        {
            var      userID = _userManagerService.GetUserId(User);
            Customer cust   = _customerService.GetQuery(c => c.UserId == userID);
            IEnumerable <Address> addList = _addressService.GetAll();

            CustomerEditViewModel vm = new CustomerEditViewModel
            {
                FirstName = cust.FirstName,
                LastName  = cust.LastName,
                Email     = cust.Email,
                Address   = cust.Address,
                Suburb    = cust.Suburb,
                State     = cust.State,
                Postcode  = cust.Postcode
            };

            return(View(vm));
        }
Exemplo n.º 13
0
        public async Task <IActionResult> EditAccount(CustomerEditViewModel model)
        {
            //var user = await userManager.GetUserAsync(User);

            //            if (model.userEmail != user.Email)
            //          {
            //            return NotFound();
            //      }
            Customer customer = new Customer
            {
                FirstName  = model.FirstName,
                LastName   = model.LastName,
                StreetName = model.StreetName,
                City       = model.City,
                Parish     = model.Parish,
                Country    = model.Country,
            };

            var appuser = new AppUser
            {
                userFirstName  = model.FirstName,
                userLastName   = model.LastName,
                userStreetName = model.StreetName,
                userCity       = model.City,
                userParish     = model.Parish,
                userCountry    = model.Country
            };

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(customer);
                    _context.Update(appuser);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    return(NotFound());
                }
            }
            return(View(customer));
        }
        public ActionResult Create(CustomerEditViewModel vm)
        {
            if (ModelState.IsValid)
            {
                //密碼加密
                string salt       = Guid.NewGuid().ToString();
                byte[] pwdAndSalt = Encoding.UTF8.GetBytes(vm.Customer.Password + salt);
                byte[] hashBytes  = new SHA256Managed().ComputeHash(pwdAndSalt);
                string hash       = Convert.ToBase64String(hashBytes);
                vm.Customer.Password = hash;

                客戶資料 newData = vm.Customer;
                CustomerRepo.Add(newData);
                CustomerRepo.UnitOfWork.Commit();
                return(RedirectToAction("Index"));
            }

            return(View(vm));
        }
Exemplo n.º 15
0
        public IActionResult Create(CustomerEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                var customer = new Customer
                {
                    FirstName       = model.FirstName,
                    LastName        = model.LastName,
                    PhoneNumber     = model.PhoneNumber,
                    OptInNewsletter = model.OptInNewsletter,
                    Type            = model.Type
                };
                _customerData.Add(customer);

                return(RedirectToAction(nameof(Details), new { id = customer.Id }));
            }

            return(View());
        }
Exemplo n.º 16
0
        public IActionResult Edit(int id)
        {
            var customer = _customerData.Get(id);

            if (customer == null)
            {
                return(RedirectToAction(nameof(Index)));
            }
            var model = new CustomerEditViewModel
            {
                FirstName       = customer.FirstName,
                LastName        = customer.LastName,
                PhoneNumber     = customer.PhoneNumber,
                OptInNewsletter = customer.OptInNewsletter,
                Type            = customer.Type
            };

            return(View(model));
        }
        public IActionResult Create(CustomerEditViewModel model)
        {
            if (ModelState.IsValid)
            { //the validation attributes all pass
                var customer = new Customer
                {
                    FirstName       = model.FirstName,
                    LastName        = model.LastName,
                    PhoneNumber     = model.PhoneNumber,
                    OptInNewsletter = model.OptInNewsletter,
                    Type            = model.Type
                };
                _customerData.Add(customer);

                return(RedirectToAction(nameof(Details), new { id = customer.Id }));
            }
            //one or more validations did not pass.
            return(View());
        }
Exemplo n.º 18
0
 public async Task <ActionResult> Create(CustomerEditViewModel customerEditViewModel)
 {
     try
     {
         if (SaveObject <Customer>(customerEditViewModel.ModelObject, false))
         {
             return(RedirectToAction("Index"));
         }
         else
         {
             return(View(customerEditViewModel));
         }
     }
     catch (DataException /* dex */)
     {
         //Log the error (uncomment dex variable name and add a line here to write a log.
         ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
     }
     return(RedirectToAction("Index"));
 }
Exemplo n.º 19
0
        public ActionResult Create([Bind(Include = "CustomerID, CustomerName, SelectedCountryIso3, SelectedRegionCode")] CustomerEditViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    bool saved = CustomerRepo.SaveCustomer(model);

                    if (saved)
                    {
                        return(RedirectToAction("Index"));
                    }
                }


                throw new ApplicationException("Invalid Model");
                // return View("Index");
            }
            catch (ApplicationException ex) { throw ex; }
        }
Exemplo n.º 20
0
 public ActionResult Create([Bind(Include = "CustomerID, CustomerName, SelectedCountryIso3, SelectedRegionCode")] CustomerEditViewModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var  repo  = new CustomersRepository();
             bool saved = repo.SaveCustomer(model);
             if (saved)
             {
                 return(RedirectToAction("Index"));
             }
         }
         return(View());
     }
     catch
     {
         return(View());
     }
 }
Exemplo n.º 21
0
        public async Task <IActionResult> Edit(int id, CustomerEditViewModel editModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(editModel));
            }

            var customer = await _context.Customer.SingleOrDefaultAsync(m => m.ID == id);

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

            var isAuthorized = await _authorizationService.AuthorizeAsync(User, customer, TaxiCompanyOperations.Update);

            if (!isAuthorized.Succeeded)
            {
                return(new ChallengeResult());
            }

            customer = ViewModel_to_model(customer, editModel);

            if (customer.Status == Customer.CustomerStatus.Approved)
            {
                // If the update is updated after approval,
                // and the user cannot approve set the status back to submitted
                var canApprove = await _authorizationService.AuthorizeAsync(User, customer, TaxiCompanyOperations.Approve);

                if (!canApprove.Succeeded)
                {
                    customer.Status = Customer.CustomerStatus.Submitted;
                }
            }

            _context.Update(customer);
            await _context.SaveChangesAsync();

            ViewData["BranchID"] = new SelectList(_context.Branch, "ID", "City", customer.BranchID);
            return(RedirectToAction("Index"));
        }
Exemplo n.º 22
0
        public ActionResult Edit(CustomerEditViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                using (var context = dataContextFactory.CreateByUser())
                {
                    var customer = (from x in context.Customers where x.ObjectId == viewModel.Customer.ObjectId select x).SingleOrDefault();

                    if (customer == null)
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
                    }

                    viewModel.ToEntity(customer);

                    context.SaveChanges();
                }
                return(RedirectToAction("Index"));
            }
            return(View(viewModel));
        }
Exemplo n.º 23
0
        public ActionResult Edit(int id)
        {
            testtEntities         pe   = new testtEntities();
            customer1             item = pe.customer1.Where(x => x.sr == id).FirstOrDefault();
            CustomerEditViewModel obj  = new CustomerEditViewModel();

            obj.sr          = item.sr;
            obj.CompanyName = item.CompanyName;
            obj.GSTIN       = item.GSTIN;
            obj.StartDate   = item.StartDate;

            obj.StartDate     = item.StartDate;
            obj.EndDate       = item.EndDate;
            obj.TurnoveAmount = item.TurnoveAmount;
            obj.ContactEmail  = item.ContactEmail;
            obj.ContactNumber = item.ContactNumber;



            return(View(obj));
        }
Exemplo n.º 24
0
        public ActionResult Edit([Bind(Include = "Id,FirstName,LastName,Email,StreetName,StreetNumber,Country,ZipCode")] CustomerEditViewModel postCustomerEditViewModel)
        {
            if (postCustomerEditViewModel == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            if (ModelState.IsValid)
            {
                //Use AutoMapper to copy properties from ViewModel to Entities.
                Customer customer = Mapper.Map <Customer>(postCustomerEditViewModel);
                Address  address  = Mapper.Map <Address>(postCustomerEditViewModel);
                customer.Address = address;

                _manager.Update(customer);
                _addressManager.Update(address);

                return(RedirectToAction("Index"));
            }
            return(View(postCustomerEditViewModel));
        }
Exemplo n.º 25
0
        public ActionResult AddressAdd(CustomerEditViewModel model)
        {
            var validator = new AddressAddValidator().Validate(model.Address);

            if (validator.IsValid)
            {
                model.Address.CreatedOnUtc = DateTime.Now;
                _unitOfWork.GetRepo <Address>().Add(model.Address);
            }
            var isSuccess = _unitOfWork.Commit();

            TempData["IsSuccess"] = isSuccess;
            TempData["Message"]   = isSuccess ? "Adres ekleme işlemi başarılı bir şekilde gerçekleştirildi." : "Adres ekleme işlemi gerçekleştirilemedi lütfen tekrar deneyiniz.";
            validator.Errors.ToList().ForEach(a =>
            {
                ModelState.AddModelError("Address." + a.PropertyName, a.ErrorMessage);
            });
            TempData["ModelState"] = ModelState;

            return(RedirectToAction("Edit", new { id = model.Address.CustomerId }));
        }
Exemplo n.º 26
0
        // GET: Customers/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Customer customer = _manager.ReadOne(id.GetValueOrDefault());

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

            //Map our information from entities to ViewModel.
            CustomerEditViewModel postCustomerEditViewModel = Mapper.Map <CustomerEditViewModel>(customer);

            postCustomerEditViewModel = Mapper.Map(customer.Address, postCustomerEditViewModel);

            return(View(postCustomerEditViewModel));
        }
Exemplo n.º 27
0
 public IActionResult Edit(int?id)
 {
     if (id != null && id > 0)
     {
         Customer extingCustomer = _customerManager.GetById(id);
         if (extingCustomer != null)
         {
             CustomerEditViewModel editViewModel = new CustomerEditViewModel
             {
                 Id            = extingCustomer.Id,
                 Name          = extingCustomer.Name,
                 Email         = extingCustomer.Email,
                 Phone         = extingCustomer.Phone,
                 Address       = extingCustomer.Address,
                 ExistingPhoto = extingCustomer.PhotoPath
             };
             return(View(editViewModel));
         }
     }
     return(View());
 }
Exemplo n.º 28
0
 public ActionResult Create(CustomerEditViewModel model)
 {
     if (ModelState.IsValid)
     {
         if (_customerRepository.GetByPersonNummer(model.PersonNummer) != null)
         {
             ModelState.AddModelError("PersonNummer", "Finns redan");
         }
         else
         {
             _customerRepository.Add(new Customer {
                 PersonNummer = model.PersonNummer, Name = model.Namn
             });
             _eventChannel.Publish(new NewCustomerCreated {
                 PersonNummer = model.PersonNummer
             });
             return(RedirectToAction(nameof(Index)));
         }
     }
     return(View(model));
 }
Exemplo n.º 29
0
        public ActionResult Edit(int id)
        {
            CustomerEditViewModel model = new CustomerEditViewModel();
            DataTable             dt    = CMSService.SelectSome("Customer", "CMSCustomer", "CustomerId=" + id);

            foreach (DataRow dr in dt.Rows)
            {
                CustomerDto dto = CustomerMapping.getDTO(dr);
                model.CustomerName         = dto.CustomerName;
                model.CustomerNumber       = dto.CustomerNumber;
                model.CustomerBirthday     = dto.CustomerBirthday.ToShortDateString();
                model.CustomerSex          = dto.CustomerSex;
                model.CustomerId           = dto.CustomerId;
                model.CustomerTelephone    = dto.CustomerTelephone;
                model.CustomerEmail        = dto.CustomerEmail;
                model.CustomerMinzu        = dto.CustomerMinzu;
                model.CustomerChangzhu     = dto.CustomerChangzhu;
                model.CustomerWenhua       = dto.CustomerWenhua;
                model.CustomerHunyin       = dto.CustomerHunyin;
                model.CustomerZhiye        = dto.CustomerZhiye;
                model.CustomerAddress      = dto.CustomerAddress;
                model.CustomerHujiAddress  = dto.CustomerHujiAddress;
                model.CustomerXiangzhen    = dto.CustomerXiangzhen;
                model.CustomerJuweihui     = dto.CustomerJuweihui;
                model.CustomerLianxiren    = dto.CustomerLianxiren;
                model.CustomerLianxirenTel = dto.CustomerLianxirenTel;
                model.CustomerBeizhu       = dto.CustomerBeizhu;
                model.CustomerYongyao      = dto.CustomerYongyao;
                model.CustomerShequ        = dto.CustomerShequ;
                model.CustomerDoctor       = dto.CustomerDoctor;
            }
            ViewData["CChangzhu"] = CustomerService.GetChangzhuSelectList();
            ViewData["CHunyin"]   = CustomerService.GetHunyinSelectList();
            ViewData["CMinzu"]    = CustomerService.GetMinzuSelectList();
            ViewData["CZhiye"]    = CustomerService.GetZhiyeSelectList();
            ViewData["CWenhua"]   = CustomerService.GetWenhuaSelectList();
            ViewData["Category"]  = MyService.GetCategorySelectList("CategoryParentId=36");
            ViewData["Doctor"]    = MyService.GetUserSelectList("charindex('47',UserRoles)>0");
            return(View(model));
        }
Exemplo n.º 30
0
        public IActionResult Edit(CustomerEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                var customer = _customerData.Get(model.Id);
                if (customer == null)
                {
                    return(RedirectToAction(nameof(Index)));
                }

                customer.FirstName       = model.FirstName;
                customer.LastName        = model.LastName;
                customer.PhoneNumber     = model.PhoneNumber;
                customer.OptInNewsletter = model.OptInNewsletter;
                customer.Type            = model.Type;

                _customerData.Update(customer);
                return(RedirectToAction(nameof(Details), new { id = customer.Id }));
            }

            return(View());
        }