public async Task <ActionResult> Edit(EditCustomerViewModel vm) { if (!ModelState.IsValid) { vm.Subscriptions = await _context.Subscriptions.ToListAsync(); return(View(vm)); } if (User.IsInRole("Admin")) { Customer customerInDb = await _context.Customers.Include(c => c.Subscription).FirstOrDefaultAsync(c => c.Id.Equals(vm.Id)); customerInDb.Firstname = vm.Firstname; customerInDb.Lastname = vm.Lastname; customerInDb.Email = vm.Email; customerInDb.Subscription = await _context.Subscriptions.FirstOrDefaultAsync(s => s.Id.Equals(vm.SubscriptionId)); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(HttpNotFound()); }
public async Task <IActionResult> EditCustomer() { bool IsUserAuthenticated = HttpContext.User.Identity.IsAuthenticated; if (IsUserAuthenticated) { string userName = HttpContext.User.Identity.Name; ApplicationUser user = await _userManagerService.FindByNameAsync(userName); Customer customer = _customerRepo.GetSingle(c => c.UserId == user.Id); EditCustomerViewModel vm = new EditCustomerViewModel { Username = user.UserName, Phone = user.PhoneNumber, Email = user.Email, FirstName = customer.FirstName, LastName = customer.LastName }; return(View(vm)); } return(Content("Must be logged in!")); }
public async Task <IActionResult> Edit(EditCustomerViewModel model) { if (ModelState.IsValid) { long customerId = model.CustomerID; Customer customer = await this.CustomerService.GetCustomerAsync(customerId); customer.NameStyle = model.NameStyle; customer.Title = model.Title; customer.FirstName = model.FirstName; customer.MiddleName = model.MiddleName; customer.LastName = model.LastName; customer.Suffix = model.Suffix; customer.CompanyName = model.CompanyName; customer.SalesPerson = model.SalesPerson; customer.EmailAddress = model.EmailAddress; customer.Phone = model.Phone; await this.CustomerService.UpdateCustomerAsync(customer); return(RedirectToAction(nameof(Index))); } return(View(model)); }
public async Task <IActionResult> Edit(string id) { if (id == null) { return(NotFound()); } var customer = await _context.Users.SingleOrDefaultAsync(m => m.Id == id); if (customer == null) { return(NotFound()); } var model = new EditCustomerViewModel { Forename = customer.Forename, MiddleNames = customer.MiddleNames, Surname = customer.Surname, Email = customer.Email, DateOfBirth = customer.DateOfBirth }; return(View(model)); }
public ActionResult Edit(int id) { var customer = _repo.GetCustomer(id); if (customer == null) { return(HttpNotFound()); } var form = new EditCustomerViewModel() { UserId = customer.User.Id, UserName = customer.User.UserName, CustomerId = customer.Id, FirstName = customer.User.FirstName, LastName = customer.User.LastName, Email = customer.User.Email, PhoneNumber = customer.User.PhoneNumber, Avatar = customer.User.Avatar, NationalCode = customer.NationalCode, Address = customer.Address, PostalCode = customer.PostalCode, GeoDivisionId = customer.GeoDivisionId }; ViewBag.GeoDivisionId = new SelectList(_geoDivisonsRepo.GetGeoDivisionsByType((int)GeoDivisionType.State), "Id", "Title", form.GeoDivisionId); return(View(form)); }
public ActionResult EditMyProfile() { var customer = _customerRepo.GetCurrentCustomer(); if (customer == null) { return(HttpNotFound()); } var form = new EditCustomerViewModel() { UserId = customer.User.Id, UserName = customer.User.UserName, CustomerId = customer.Id, FirstName = customer.User.FirstName, LastName = customer.User.LastName, Email = customer.User.Email, PhoneNumber = customer.User.PhoneNumber, Avatar = customer.User.Avatar, NationalCode = customer.NationalCode, Address = customer.Address, PostalCode = customer.PostalCode }; return(View(form)); }
public void ShowWindow(BaseViewModel viewModel, bool showAsDialog) { Window window = viewModel switch { // Wenn viewModel null ist -> ArgumentNullException null => throw new ArgumentNullException(nameof(viewModel)), MainViewModel _ => new MainWindow(), EditCustomerViewModel _ => new EditCustomerWindow(), // default -> InvalidOperationException _ => throw new InvalidOperationException($"Unbekanntes ViewModel '{viewModel}'"), }; _windows[viewModel] = window; window.DataContext = viewModel; if (showAsDialog) { window.ShowDialog(); } else { window.Show(); } }
public EditCustomerViewModel GetEditVm(string customerName) { ApplicationUser user = this.Context.Users.FirstOrDefault(apuser => apuser.UserName == customerName); EditCustomerViewModel vm = Mapper.Map <ApplicationUser, EditCustomerViewModel>(user); return(vm); }
public ActionResult Save(EditCustomerViewModel cust) { var agent=_context.Agents.FirstOrDefault(a => a.AgentCode == cust.AgentCode); if (agent == null) { ModelState.AddModelError("", "Agent doesn't exists"); cust.Citylist = cities; cust.Countrylist = countries; return View("CustForm", cust); } var param = new List<object>(){ new SqlParameter("@CustCode",cust.CustomerCode), new SqlParameter("@FirstName",cust.FirstName), new SqlParameter("@LastName",cust.LastName), new SqlParameter("@CustomerCity",cust.CustomerCity), new SqlParameter("@WorkingArea",cust.WorkingArea), new SqlParameter("@CustomerCountry",cust.CustomerCountry), new SqlParameter("@Grade",cust.Grade), new SqlParameter("@OpeningAmount",cust.OpeningAmount), new SqlParameter("@PhoneNo",cust.PhoneNo), new SqlParameter("@AgentCode",cust.AgentCode), }; _context.Database.ExecuteSqlCommand( "exec InsertUpdateCustomer @CustCode,@FirstName,@LastName,@CustomerCity,@WorkingArea,@CustomerCountry,@Grade,@OpeningAmount,@PhoneNo,@AgentCode", param.ToArray()); return RedirectToAction("Index"); }
public ActionResult Edit(int id) { try { // get customer info var editedCustomer = db.Customers.Where(c => c.CustomerId == id).FirstOrDefault(); if (editedCustomer != null) { // Create view model EditCustomerViewModel model = new EditCustomerViewModel(); model.CustomerId = editedCustomer.CustomerId; model.CustomerName = editedCustomer.CustomerName; model.Description = editedCustomer.Description; return(View(model)); } else { return(RedirectToAction("Message", "Error", new RouteValueDictionary(new { message = "đơn vị #" + id + " không tồn tại trong hệ thống!" }))); } } catch (Exception ex) { return(RedirectToAction("Message", "Error", new RouteValueDictionary(new { message = ex.Message }))); } }
public EditCustomerViewModel GetCustomerForEdit(int id) { Customer customer = this.Context.Customers.Find(id); EditCustomerViewModel mappedcustomer = Mapper.Map <Customer, EditCustomerViewModel>(customer); return(mappedcustomer); }
public AccountModel(ISessionHelper sessionHelper, IHttpClientFactory clientFactory, ICustomerFactory customerFactory) { this.sessionHelper = sessionHelper; this.clientFactory = clientFactory; this.customerFactory = customerFactory; FormData = new EditCustomerViewModel(); }
public async Task <IActionResult> EditCustomer(EditCustomerViewModel vm) { if (ModelState.IsValid) { ApplicationUser specificUser = await _userManagerService.FindByNameAsync(vm.Username); specificUser.PhoneNumber = vm.Phone; specificUser.Email = vm.Email; IdentityResult result = await _userManagerService.UpdateAsync(specificUser); if (result.Succeeded) { Customer updatedCustomer = _customerRepo.GetSingle(c => c.UserId == specificUser.Id); updatedCustomer.FirstName = vm.FirstName; updatedCustomer.LastName = vm.LastName; _customerRepo.Update(updatedCustomer); return(RedirectToAction("Index", "Packages")); } else { foreach (var err in result.Errors) { //ModelState.AddModelError("" , "error"); ModelState.AddModelError("", err.Description); } } } return(View(vm)); }
public async Task <IActionResult> Edit(EditCustomerViewModel model) { if (!ModelState.IsValid) { return(View()); } if (string.IsNullOrWhiteSpace(model.CustomerId)) { throw new ApplicationException("Can't edit customer with id null"); } var customer = await _customerService.GetCustomerById(model.CustomerId); if (customer != null) { customer.FullName = model.FullName; var updateCustomer = await _customerService.UpdateCustomer(customer); if (updateCustomer) { var customerId = model.CustomerId; return(RedirectToAction(nameof(CustomerController.Detail), "Customer", new { customerId })); } } ModelState.AddModelError(string.Empty, Model.Resources.ValidationMessages.ResourceManager.GetString("EditCustomerError")); return(View()); }
// GET: /Customer/Edit public ActionResult EditCustomer(string id, AccountController.ManageMessageId?message = null) { using (var db = new ApplicationDbContext()) { Customer customer = unitOfWork.Customers.FindById(id); var model = new EditCustomerViewModel(); model.CustomerId = customer.CustomerId; model.UserName = customer.User.UserName; model.FirstName = customer.User.FirstName; model.MiddleName = customer.User.MiddleName; model.LastName = customer.User.LastName; model.Email = customer.User.Email; model.RoleName = unitOfWork.Customers.GetRole(customer.CustomerId); var cusRoles = new ApplicationDbContext().Roles.Where(role => role.Name != "Admin").ToList(); foreach (var role in cusRoles) { model.Roles.Add(new SelectListItem { Text = role.Name, Value = role.Name }); } ViewBag.MessageId = message; return(View(model)); } }
//returns the edit page of a customer public async Task <IActionResult> EditCustomer(int?id) { var response = await NwbaApi.InitializeClient().GetAsync("api/customers/" + id); if (!response.IsSuccessStatusCode) { return(RedirectToAction($"StatusCode/{response.StatusCode}")); } var result = response.Content.ReadAsStringAsync().Result; var customer = JsonConvert.DeserializeObject <CustomerDto>(result); response = await NwbaApi.InitializeClient().GetAsync("api/logins/"); result = response.Content.ReadAsStringAsync().Result; var logins = JsonConvert.DeserializeObject <List <Login> >(result); try { var login = logins.Where(x => x.CustomerID == customer.CustomerID).FirstOrDefault(); var customerViewModel = new EditCustomerViewModel(customer, login.Status); return(View(customerViewModel)); } catch { return(RedirectToAction($"StatusCode/" + 204)); } }
public async Task <IActionResult> EditCustomer(EditCustomerViewModel customerViewModel) { if (ModelState.IsValid) { var content = new StringContent(JsonConvert.SerializeObject(customerViewModel.Customer), Encoding.UTF8, "application/json"); var response = NwbaApi.InitializeClient().PutAsync("api/customers", content).Result; response = await NwbaApi.InitializeClient().GetAsync("api/logins/"); var result = response.Content.ReadAsStringAsync().Result; var logins = JsonConvert.DeserializeObject <List <Login> >(result); var login = logins.Where(x => x.CustomerID == customerViewModel.Customer.CustomerID).FirstOrDefault(); login.Status = customerViewModel.LoginStatus; login.LockedUntil = customerViewModel.LockedUntil; content = new StringContent(JsonConvert.SerializeObject(login), Encoding.UTF8, "application/json"); response = NwbaApi.InitializeClient().PutAsync("api/logins", content).Result; if (!response.IsSuccessStatusCode) { throw new Exception(); } if (response.IsSuccessStatusCode) { return(RedirectToAction(nameof(ViewCustomers))); } } return(RedirectToAction(nameof(ViewCustomers))); }
public virtual ActionResult Edit(EditCustomerViewModel viewModel) { if (!ModelState.IsValid) { ModelState.AddModelError("", "تمام فیلد ها باید وارد شوند."); return(View(viewModel)); } try { ServiceFactory.Create <ICustomerService>() .Save(new Customer { FirstName = viewModel.FirstName, LastName = viewModel.LastName, PhoneNumber = viewModel.PhoneNumber, Id = viewModel.Id, Version = viewModel.Version }); } catch (DbUpdateConcurrencyException) { ModelState.AddModelError("", "اطلاعات کاریر مورد نظر توسط کاربر دیگری در شبکه، تغییر یافته است. برای ادامه صفحه را رفرش کنید."); return(View(viewModel)); } return(RedirectToAction("List")); }
public IActionResult Edit(EditCustomerViewModel customerViewModel) { Customer customer = new Customer(); if (ModelState.IsValid) { customer.Id = customerViewModel.Id; customer.Name = customerViewModel.Name; customer.Address = customerViewModel.Address; customer.Telephone = customerViewModel.Telephone; customer.Email = customerViewModel.Email; customer.HomePage = customerViewModel.HomePage; customer.IndustrialClassification = customerViewModel.IndustrialClassification; customer.Subsidiaries = customerViewModel.Subsidiaries; customer.CVR = customerViewModel.CVR; customer.Responsible = customerViewModel.Responsible; customer.ResponsibleEmail = customerViewModel.ResponsibleEmail; customer.ResponsibleTelephone = customerViewModel.ResponsibleTelephone; customer.IsPBSPayment = customerViewModel.IsPBSPayment; if (customerViewModel.IsPBSPayment) { customer.RegistrationNumber = customerViewModel.RegistrationNumber; customer.AccountNumber = customerViewModel.AccountNumber; } customer.MultiannualAgreement = customerViewModel.MultiannualAgreement; customer.Forwards = customerViewModel.Forwards; customer.Activities = customerViewModel.Activities; customerService.Save(customer); return(RedirectToAction("Index")); } return(View(customer)); }
public ActionResult Edit(EditCustomerViewModel customer) { if (ModelState.IsValid) { var dbCust = getCustomerByUsername(Session["CurrentCustomerUsername"].ToString()); var pwdHash = Cryptography.Hash(customer.ConfirmationPassword); if (dbCust.PasswordHash.Equals(pwdHash)) { dbCust.Firstname = customer.Firstname; dbCust.Lastname = customer.Lastname; dbCust.Street = customer.Street; dbCust.Housenumber = customer.Housenumber; dbCust.City = customer.City; dbCust.Zipcode = customer.Zipcode; dbCust.PhoneNumber = customer.PhoneNumber; dbCust.EmailAddress = customer.EmailAddress; db.SaveChanges(); return(RedirectToAction("Edit")); } else { ModelState.AddModelError(string.Empty, "Ungültiges Passwort"); } } else { ModelState.AddModelError(string.Empty, "Ungültige Daten"); } return(View("Edit")); }
public ActionResult Edit(EditCustomerViewModel edtcust) { Response _response = new Response(); _response.Status = 0; _response.Message = "资料添写失败"; if (!ModelState.IsValid) { _response.Status = 0; _response.Message = General.GetModelErrorString(ModelState); } else { Customer _customer = cusManager.FindByAccount(Session["username"].ToString()); _customer.Contacts = edtcust.Contacts; //取消掉了修改公司名的功能 // _customer.CorporateName = edtcust.CorporateName; _customer.Email = edtcust.Email; _customer.Address = edtcust.Address; _response = cusManager.Update(_customer); _response.Url = Url.Action("edit"); _response.Message = "恭喜您!修改成功!"; } return(Json(_response)); }
public ActionResult Edit() { string customerName = this.User.Identity.Name; EditCustomerViewModel vm = this.service.GetEditVm(customerName); return(this.View(vm)); }
public async Task <IActionResult> EditCustomer(EditCustomerViewModel viewModel) { if (!ModelState.IsValid) { return(View(viewModel)); } var customer = (Customer)_manager.GetAll().Where(x => x.Id == viewModel.Id).FirstOrDefault(); if (customer != null) { customer.Name = viewModel.Name; if (!string.IsNullOrEmpty(viewModel.ProductOwnerId)) { var newProductOwner = await _manager.GetProductOwnerAsync(viewModel.ProductOwnerId); if (newProductOwner != null) { customer.ProductOwner = newProductOwner; } } await _manager.SaveChangesAsync(); } return(RedirectToAction("Index")); }
protected override void OnAppearing() { base.OnAppearing(); var editCustomer = EditCustomerViewModel.GetInstance(); editCustomer.RefreshShipTo(); }
public void Update(EditCustomerViewModel model) { var entity = this.customerRepository.GetById(model.Id); this.mapper.Map(model, entity); this.customerRepository.Update(entity); this.customerRepository.SaveChanges(); }
public async Task <ActionResult> EditCustomerModal(Guid customerId) { var output = await _customerAppService.GetById(customerId); var model = new EditCustomerViewModel(output); return(View("_EditCustomerModal", model)); }
private void CustomerEditStart(Customer obj) { var customerEditViewModel = new EditCustomerViewModel(obj, _dataService, _users); var customerEditView = new EditCustomerViewWindow(); customerEditView.ViewModel = (customerEditViewModel); customerEditView.Show(); }
public ActionResult Edit(EditCustomerViewModel model) { if (ModelState.IsValid) { _repository.Update(model); return(RedirectToAction("CustomerList")); } return(View(model)); }
protected override void ShowChild() { Thread.Sleep(2000); var nameTokens = FullName.Trim().Split(); var editCustomerViewModel = new EditCustomerViewModel(new CustomerViewModel(nameTokens[0], nameTokens[1])); var result = DialogService.ShowModal<EditCustomerViewModel, string>(editCustomerViewModel); DialogService.ShowMessage("Window closed", "Value returned:\r\n" + result); }
public void Update(EditCustomerViewModel model) { var customer = _dbContext.Customers.Single(x => x.Id == model.Id); customer.lastName = model.LastName; customer.Name = model.Name; customer.Phone = model.Phone; _dbContext.SaveChanges(); }
public async Task <CustomerViewModel> EditCustomerAsync(EditCustomerViewModel model) { var customerEntity = CustomerMapper.Map(model); var customer = await customerRepository.EditCustomerAsync(customerEntity); var result = CustomerMapper.Map(customer); return(result); }