public ActionResult DeleteConfirmed(int id)
        {
            CustomerBaseViewModel customerBaseViewModel = db.CustomerBaseViewModels.Find(id);

            db.CustomerBaseViewModels.Remove(customerBaseViewModel);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "UserID,UserName")] CustomerBaseViewModel customerBaseViewModel)
 {
     if (ModelState.IsValid)
     {
         db.Entry(customerBaseViewModel).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(customerBaseViewModel));
 }
        public ActionResult Create([Bind(Include = "UserID,UserName")] CustomerBaseViewModel customerBaseViewModel)
        {
            if (ModelState.IsValid)
            {
                db.CustomerBaseViewModels.Add(customerBaseViewModel);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(customerBaseViewModel));
        }
        public async Task <IActionResult> Create(CustomerBaseViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            await this.customers.CreateAsync(model.FirstName, model.LastName, model.IsMale, model.PhoneNumber);

            TempData.AddSuccessMessage("Successfully created new customer!");

            return(this.RedirectToCustomAction(nameof(Index)));
        }
        // GET: CustomerBaseViewModels/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CustomerBaseViewModel customerBaseViewModel = db.CustomerBaseViewModels.Find(id);

            if (customerBaseViewModel == null)
            {
                return(HttpNotFound());
            }
            return(View(customerBaseViewModel));
        }
        public async Task <IActionResult> Edit(CustomerBaseViewModel model)
        {
            var customer = await this.customers.GetByIdAsync(model.Id);

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

            await this.customers.UpdateAsync(model.Id, model.FirstName, model.LastName, model.PhoneNumber, customer.Status);

            TempData.AddSuccessMessage($"Successfully updated customer {model.FirstName}!");

            return(this.RedirectToCustomAction(nameof(Index)));
        }
        private static CustomerBaseViewModel ConvertToBaseViewModel(Customer dbModel)
        {
            var viewModel = new CustomerBaseViewModel
            {
                Id            = dbModel.Id,
                user          = UserDto.FromModel(dbModel.user),
                country       = CountryDto.FromModel(dbModel.country),
                Address1      = dbModel.Address1,
                Address2      = dbModel.Address2,
                PaymentMethod = dbModel.PaymentMethod,
                Enabled       = dbModel.Enabled,
            };


            return(viewModel);
        }