Beispiel #1
0
        public async Task <IActionResult> Edit(ManageCustomerModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var customer = _dbContext.Customers.Single(x => x.Id == model.Customer.Id);

            customer.Address   = model.Customer.Address;
            customer.Att       = model.Customer.Att;
            customer.City      = model.Customer.City;
            customer.Email     = model.Customer.Email;
            customer.VATNumber = model.Customer.VATNumber;
            customer.Zip       = model.Customer.Zip;
            customer.Name      = model.Customer.Name;
            customer.Phone     = model.Customer.Phone;

            if (model.User != null)
            {
                var user = _dbContext.Users.Single(x => x.Id == model.User.Id);
                user.Customer = customer;
                _dbContext.Update(user);
            }

            await _dbContext.SaveChangesAsync();

            model = CreateCustomerEditModel(model.Customer.Id);

            return(View(model));
        }
Beispiel #2
0
 public CustomCommand(MainWindowViewModel viewmodel, ServiceProvider serviceProvider)
 {
     this.serviceProvider = serviceProvider;
     this.viewmodel       = viewmodel;
     //Making sure the models will be able to fire their commands and recognise the API
     addModel    = new AddCustomerModel(serviceProvider);
     deleteModel = new DeleteCustomerModel(serviceProvider);
     manageModel = new ManageCustomerModel(serviceProvider);
     //Empowering more intuitive DataGrids
     deleteModel.Api.GetTable <UserReadDto>("users");
     manageModel.Api.GetTable <UserReadDto>("users");
 }
        public IActionResult Edit(int customerId)
        {
            Customer customer = _dbContext.Customers.Single(x => x.Id == customerId);
            var      users    = _dbContext.Users.ToList();
            var      model    = new ManageCustomerModel()
            {
                Customer      = customer,
                Users         = users,
                StatusMessage = StatusMessage
            };

            return(View(model));
        }
Beispiel #4
0
        private ManageCustomerModel CreateCustomerEditModel(int?customerId)
        {
            Customer customer = _dbContext.Customers.Single(x => x.Id == customerId);
            var      users    = _dbContext.Users.ToList();
            var      model    = new ManageCustomerModel()
            {
                Customer      = customer,
                Users         = users,
                StatusMessage = StatusMessage
            };

            return(model);
        }
        public async Task <IActionResult> Edit(ManageCustomerModel model)
        {
            var customer = _dbContext.Customers.Single(x => x.Id == model.Customer.Id);
            var user     = _dbContext.Users.Single(x => x.Id == model.User.Id);

            user.Customer = customer;

            _dbContext.Update(user);

            await _dbContext.SaveChangesAsync();

            model.Users = customer.Users.ToList();

            return(View(model));
        }
Beispiel #6
0
        public IActionResult Edit(int?customerId)
        {
            if (customerId == null)
            {
                var userId = _userManager.GetUserId(User);

                var             dbUser    = _dbContext.Users.Single(x => x.Id == userId);
                List <Customer> customers = _dbContext.Customers.Where(x => x.DeleteDate.HasValue == false).ToList();

                customerId = dbUser.Customer.Id;
            }

            ManageCustomerModel model = CreateCustomerEditModel(customerId);

            return(View(model));
        }