private string ProcessUploadedFile(CustomerCreateViewModel model) { string uniqueFileName = null; // Store the file name in PhotoPath property of the customer object // which gets saved to the Customer database table // If the Photo property on the incoming model object is not null, then the user // has selected an image to upload. if (model.Photo != null) { // The image must be uploaded to the images folder in wwwroot // To get the path of the wwwroot folder we are using the inject // HostingEnvironment service provided by ASP.NET Core string uploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath, "images"); // To make sure the file name is unique we are appending a new // GUID value and and an underscore to the file name uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Photo.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); // Use CopyTo() method provided by IFormFile interface to // copy the file to wwwroot/images folder using (var fileStream = new FileStream(filePath, FileMode.Create)) { model.Photo.CopyTo(fileStream); } } return(uniqueFileName); }
public ActionResult Edit(string id) { if (string.IsNullOrEmpty(id)) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var customerService = new StripeCustomerService(); var stripeCustomer = customerService.Get(id); var applicationUser = UserManager.FindByEmail(stripeCustomer.Email); var customer = new CustomerCreateViewModel { Id = stripeCustomer.Id, Email = stripeCustomer.Email, Description = stripeCustomer.Description, FirstName = applicationUser.FirstName, LastName = applicationUser.LastName, PhoneNumber = applicationUser.PhoneNumber, Address = applicationUser.Address, Address2 = applicationUser.Address2, City = applicationUser.City, State = applicationUser.State, Zip = applicationUser.Zip }; return(View(customer)); }
public IActionResult Edit(int Id, [Bind("Id,Name,Address,LoyaltyPoint")] CustomerCreateViewModel customer) { if (Id != customer.Id) { return(NotFound()); } if (ModelState.IsValid) { var aCustomer = _mapper.Map <Customer>(customer); //if (_customerManager.CustomerExists(customer.Name)) //{ // ViewBag.ErrorMessage = "Customer Exists Already"; //} //else //{ bool isUpdated = _customerManager.Update(aCustomer); if (isUpdated) { var customers = _customerManager.GetAll(); ViewBag.SuccessMessage = "Updated Successfully!"; return(View("Index", customers)); } //} } else { ViewBag.ErrorMessage = "Update Failed!"; } customer.CustomerList = _customerManager.GetAll().ToList(); return(View(customer)); }
public IActionResult Create(CustomerCreateViewModel model) { if (ModelState.IsValid) { var customer = _mapper.Map <Customer>(model); //AutoMapper if (_customerManager.CustomerExists(model.Name)) { ViewBag.ErrorMessage = "Customer already Exist"; } else { bool isAdded = _customerManager.Add(customer); if (isAdded) { ViewBag.SuccessMessage = "Saved Successfully!"; } } } else { ViewBag.ErrorMessage = "Operation Failed!"; } model.CustomerList = _customerManager.GetAll().ToList(); return(View(model)); }
public ActionResult Create(CustomerCreateViewModel model) { UserManager <Customer> UserManager = new UserManager <Customer>(new UserStore <Customer>(db)); if (ModelState.IsValid) { var user = new Customer { CuS_Email = model.CuS_Email, CuS_Login = model.CuS_Email, CuS_Name = model.CuS_Name, CuS_Surname = model.CuS_Surname, CuS_PhoneNumber = model.CuS_PhoneNumber, CuS_CMPID = model.CuS_CMPID }; var chkUser = UserManager.Create(user, model.CuS_Password); if (chkUser.Succeeded) { var result1 = UserManager.AddToRole(user.Id, "Customer"); } return(RedirectToAction("List")); } model.Companies = db.Companies.ToList(); return(View(model)); }
public IActionResult Create() { CustomerCreateViewModel customer = new CustomerCreateViewModel(); customer.CustomerList = _customerManager.GetAll().Select(cust => _mapper.Map <CustomerResponseModel>(cust)).ToList(); return(View(customer)); }
public ActionResult Edit(CustomerCreateViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var customerService = new StripeCustomerService(); var stripeCustomer = customerService.Get(model.Id); var applicationUser = UserManager.FindByEmail(stripeCustomer.Email); var updateOptions = new StripeCustomerUpdateOptions { Description = model.Description }; customerService.Update(model.Id, updateOptions); applicationUser.FirstName = model.FirstName; applicationUser.LastName = model.LastName; applicationUser.PhoneNumber = model.PhoneNumber; applicationUser.Address = model.Address; applicationUser.Address2 = model.Address2; applicationUser.City = model.City; applicationUser.State = model.State; applicationUser.Zip = model.Zip; UserManager.Update(applicationUser); return(RedirectToAction("Details", new { id = model.Id })); }
public async Task <IActionResult> Create(CustomerCreateViewModel model) { try { if (ModelState.IsValid) { var customer = new CustomerCreateDTO { PhoneNumber = model.PhoneNumber, FullName = model.FullName, Email = model.Email, Gender = model.Gender, Address = model.Address }; await _customerService.Create(customer).ConfigureAwait(true); _toastNotification.AddSuccessToastMessage("Created:- " + customer.FullName); return(RedirectToAction("Index")); } } catch (Exception ex) { _toastNotification.AddErrorToastMessage(ex.Message); } return(View(model)); }
public ActionResult Edit(CustomerCreateViewModel customer) { if (ModelState.IsValid) { Customer oldCustomer = db.Customers.Include(x => x.Address).Include(x => x.PhoneNumbers) .Include(x => x.Orders).FirstOrDefault(x => x.CustomerID == customer.CustomerID); oldCustomer.FirstName = customer.FirstName; oldCustomer.LastName = customer.LastName; oldCustomer.Address = customer.Address; oldCustomer.PhoneNumbers = new List <PhoneNumber>(); List <string> phoneNumbers = customer.PhoneNumbers.Split(',').ToList(); foreach (var number in phoneNumbers) { oldCustomer.PhoneNumbers.Add(new PhoneNumber { Number = number }); } db.Entry(oldCustomer).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(customer)); }
public IActionResult Edit(int id) { if (User.FindFirstValue(ClaimTypes.NameIdentifier) == null) { return(RedirectToAction("LowPermission")); } var cus = customerService.GetById(id); if (cus == null) { return(NotFound()); } var model = new CustomerCreateViewModel() { CustomerId = cus.CustomerId, Active = cus.Active, Email = cus.Email, FirstName = cus.FirstName, LastName = cus.LastName, PhoneNum = cus.PhoneNum, AddressId = cus.AddressId, }; ViewBag.Addresses = _addressService.GetAllAddress(); return(View(model)); }
public ActionResult Create(CustomerCreateViewModel customer) { if (ModelState.IsValid) { Customer newCustomer = new Customer { Address = customer.Address, FirstName = customer.FirstName, LastName = customer.LastName, PhoneNumbers = new List <PhoneNumber>() }; List <string> phoneNumbers = customer.PhoneNumbers.Split(',').ToList(); foreach (var number in phoneNumbers) { newCustomer.PhoneNumbers.Add(new PhoneNumber { Number = number }); } db.Customers.Add(newCustomer); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(customer)); }
public async Task LoadAsync() //method must be async when loading in async data and return a task { //load list data await EquipmentListViewModel.LoadAsync(); await ComponentListViewModel.LoadAsync(); await CustomerListViewModel.LoadAsync(); await CustomerCreateViewModel.LoadEquipment(); await AddRemoveEquipmentToFromCustomerViewModel.LoadAsync(); await AddRemoveEquipmentToFromCustomerViewModel.LoadEquipmentAsync(); await EquipmentCreateViewModel.LoadTypesAsync(); await EquipmentCreateViewModel.LoadConfigurationsAsync(); await EquipmentCreateViewModel.LoadCategoriesAsync(); await EquipmentDetailViewModel.LoadTypesAsync(); await EquipmentDetailViewModel.LoadConfigurationsAsync(); await EquipmentDetailViewModel.LoadCategoriesAsync(); }
public IActionResult Create(CustomerCreateViewModel model) { if (ModelState.IsValid) { string uniqueFilename = ProcessUploadFile(model); Customer customer = new Customer { Name = model.Name, Email = model.Email, Phone = model.Phone, Address = model.Address, PhotoPath = uniqueFilename }; bool isAdd = _customerManager.Add(customer); if (isAdd) { return(RedirectToAction("Details", new { id = customer.Id })); } else { return(View()); } } return(View()); }
public async Task <IActionResult> Create(CustomerCreateViewModel model) { //This UserId is the property in Customers. We are ignoring for now because we dont want to add it to a new customer ModelState.Remove("UserId"); if (ModelState.IsValid) { string uniqueFileName = ProcessUploadedFile(model); var user = await _userManager.GetUserAsync(HttpContext.User); Customer newCustomer = new Customer { UserId = user.Id, FirstName = model.FirstName, LastName = model.LastName, StreetAddress = model.StreetAddress, City = model.City, Email = model.Email, PhoneNumber = model.PhoneNumber, Preferences = model.Preferences, PhotoPath = uniqueFileName }; _context.Add(newCustomer); await _context.SaveChangesAsync(); return(RedirectToAction("details", new { id = newCustomer.CustomerId })); } return(View(model)); }
public IActionResult Create(CustomerCreateViewModel model) { if (ModelState.IsValid) { var customer = new Customer() { Id = model.Id, Name = model.Name, Address = model.Address, LoyaltyPoint = model.LoyaltyPoint }; bool isAdded = _customerManager.Add(customer); if (isAdded) { ViewBag.SuccessMessage = "Saved Successfully"; } else { ViewBag.ErrorMessage = "Operation Failed"; } } model.CustomerList = _customerManager.GetAll(); return(RedirectToAction("Index")); }
[HttpPost("")] // ./api/customers public IActionResult Create([FromBody] CustomerCreateViewModel model) { if (model == null) { return(BadRequest()); } if (!ModelState.IsValid) { //rules failed, return a well formed error _logger.LogWarning("Customer Create failed due to validation"); return(new ValidationFailedResult(ModelState)); } var customer = new Customer { FirstName = model.FirstName, LastName = model.LastName, EmailAddress = model.EmailAddress, PhoneNumber = model.PhoneNumber, PreferredContactMethod = model.PreferredContactMethod, LastContactDate = DateTime.UtcNow }; _customerData.Add(customer); _customerData.Commit(); Response.Headers.Add("ETag", "\"" + customer.LastContactDate.ToString() + "\""); return(Ok(new CustomerDisplayViewModel(customer))); //includes new auto-assigned id }
public IActionResult Edit(int id, CustomerCreateViewModel model) { if (id != model.Id) { return(NotFound()); } var customer = new Customer() { Id = model.Id, Name = model.Name, Address = model.Address, LoyaltyPoint = model.LoyaltyPoint }; if (ModelState.IsValid) { bool isUpdate = _customerManager.Update(customer); if (isUpdate) { ViewBag.UpdateMessage = "Update SuccessFully!"; return(RedirectToAction("Index")); } } return(RedirectToAction("Index")); }
public ActionResult Create() { var model = new CustomerCreateViewModel(); model.Companies = db.Companies.ToList(); return(View(model)); }
public async Task <ActionResult> Create(CustomerCreateViewModel model) { try { var CustomerDto = new CustomerCreateDTO { PhoneNumber = model.PhoneNumber, FullName = model.FullName, Email = model.Email, Gender = model.Gender, Address = model.Address }; await _customerService.Create(CustomerDto).ConfigureAwait(true); var Customer = await _customerRepo.GetByNumber(CustomerDto.PhoneNumber) ?? throw new CustomerNotFoundException(); return(Ok(CreateReponseDto(Customer))); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public ActionResult Create(CustomerCreateViewModel model) { var m = new Customer() { CustomerCode = model.CustomerCode, State = model.State, StreetAddress = model.StreetAddress, PostCode = model.PostCode, DateOfBirth = model.DateOfBirth, FirstName = model.FirstName, PhoneNo = model.PhoneNo, Suburb = model.Suburb, MiddleName = model.MiddleName, Gender = model.Gender, LastName = model.LastName }; if (ModelState.IsValid) { try { _customerService.CreateCustomer(m); return(RedirectToAction("Index")); } catch (Exception) { throw; //ModelState.AddModelError("", ex); } } return(View(model)); }
public async Task <IActionResult> Create(CustomerCreateViewModel vm) { if (ModelState.IsValid) { try { IdentityUser user = new IdentityUser(vm.user_name); IdentityResult result = await _userManagerService.CreateAsync(user, vm.password); if (result.Succeeded) { await _userManagerService.AddToRoleAsync(user, "Customer"); //get the user back to find the id user = await _userManagerService.FindByNameAsync(vm.user_name); //return to home page return(RedirectToAction("create", "customer")); } else { foreach (var error in result.Errors) { ModelState.AddModelError("", error.Description); } } } catch (Exception ex) { Console.Write(ex.Message); throw; } } return(View(vm)); }
public IActionResult Create(CustomerCreateViewModel model) { if (ModelState.IsValid) { var customer = new Customer() { Name = model.Name, Address = model.Address, LoyaltyPoint = model.LoyaltyPoint }; bool isAdded = _customerRepository.Add(customer); if (isAdded) { ViewBag.SuccessMessage = "Saved Successfully!"; } } else { ViewBag.ErrorMessage = "Operation Failed!"; } model.CustomerList = _customerRepository.GetAll();; return(View(model)); }
//public ActionResult Create([Bind(Include = "CustomerId,LastName,FirstName,CompanyName,Phone,CellPhone,Email,VATNumber,AccountNumber,Annotation,ContactName,ContactEmail,ContactCellPhone,CreationDate,Type,TAXLiability, StreetName, StreetNumber, Box, PostalCodeId, AddressId, PostalCodeNumber,Town")] CustomerCreateViewModel ccvm) public ActionResult Create([ModelBinder(typeof(CustomerBinderCreate))] CustomerCreateViewModel ccvm) { if (ModelState.IsValid) { // aanmaken lege opbjecten Customer cus = new Customer(); CustomerDeliveryAddress cda = new CustomerDeliveryAddress(); //opslaan van klant cus = ccvm.customer; db.Customers.Add(cus); db.SaveChanges(); // vullen van delivery Address met default info cda.Box = cus.Address.Box; cda.PostalCodeNumber = cus.Address.PostalCodeNumber; cda.StreetName = cus.Address.StreetName; cda.StreetNumber = cus.Address.StreetNumber; cda.Town = cus.Address.Town; cda.CustomerId = cus.CustomerId; cda.DeliveryAddressInfo = "Standaard adres"; db.CustomerDeliveryAddresses.Add(cda); db.SaveChanges(); //redirect to index return(RedirectToAction("Index")); } return(View(ccvm)); }
public IActionResult Create() { var customers = _customerManager.GetAll(); var model = new CustomerCreateViewModel(); model.CustomerList = customers.ToList(); return(View(model)); }
public IActionResult Create() { var customers = _customerRepository.GetAll(); var model = new CustomerCreateViewModel(); model.CustomerList = customers; return(View(model)); }
public async Task <IActionResult> Create(int id) { var customer = await _customerService.GetById(id); CustomerCreateViewModel model = _mapper.Map <CustomerCreateViewModel>(customer); return(View(model)); }
public ActionResult Edit(int id) { CustomerCreateViewModel vm = new CustomerCreateViewModel(); vm.Model = _customerService.Get(id); return(View("Create", GetCreateViewModel(vm))); }
public IActionResult Create() { var model = new CustomerCreateViewModel { CustomerList = _customerManager.GetAll() }; return(PartialView(model)); }
public ActionResult Create() { CustomerCreateViewModel vm = new CustomerCreateViewModel() { Model = new CustomerDetailViewModel() }; return(View(GetCreateViewModel(vm))); }
public async Task <ActionResult> Create(CustomerCreateViewModel model) { if (ModelState.IsValid) { var customer = new StripeCustomerCreateOptions { Email = model.Email, Description = model.Description }; var customerService = new StripeCustomerService(); var stripeCustomer = customerService.Create(customer); var subscription = new Subscription { AdminEmail = model.Email, Status = SubscriptionStatus.TrialWithoutCard, StatusDetail = "Admin created with no card", StripeCustomerId = stripeCustomer.Id }; db.Subscriptions.Add(subscription); await db.SaveChangesAsync(); var user = new ApplicationUser { UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, Address = model.Address, Address2 = model.Address2, PhoneNumber = model.PhoneNumber, City = model.City, State = model.State, Zip = model.Zip, SubscriptionId = subscription.Id }; var result = await UserManager.CreateAsync(user); if (result.Succeeded) { var code = await UserManager.GeneratePasswordResetTokenAsync(user.Id); var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); await UserManager.SendEmailAsync(user.Id, "Create Password", "Please create your password by clicking <a href=\"" + callbackUrl + "\">here</a>"); return(RedirectToAction("Index")); } } return(View(model)); }