Exemplo n.º 1
0
 public int SaveCustomer(Customer customer)
 {
     var currentId = customer.Id;
     if (customer.Id == 0) {
         context.Customers.Add(customer);
         context.SaveChanges();
         currentId = (from c in context.Customers
                       orderby c.Id descending
                       select c.Id).First();
     }
     else {
         Customer dbCustomer = context.Customers.Find(customer.Id);
         if (dbCustomer != null) {
             dbCustomer.Name = customer.Name;
             dbCustomer.Adress = customer.Adress;
             dbCustomer.Email = customer.Email;
             dbCustomer.Moms = customer.Moms;
             dbCustomer.OrgNr = customer.OrgNr;
             dbCustomer.Phone1 = customer.Phone1;
             dbCustomer.Phone2 = customer.Phone2;
             dbCustomer.PostNr = customer.PostNr;
             dbCustomer.PostOrt = customer.PostOrt;
         }
     }
     context.SaveChanges();
     return currentId;
 }
Exemplo n.º 2
0
 public ActionResult CustomerDetails(int? id)
 {
     Customer selectedCustomer = new Customer();
     if (id != null)
     {
         selectedCustomer = repository.Customers.FirstOrDefault(c => c.Id == id);
     }
     return View(selectedCustomer);
 }
Exemplo n.º 3
0
 public ActionResult CustomerDetails(Customer currentCustomer)
 {
     var currentId = 0;
     if (ModelState.IsValid) {
         currentId = repository.SaveCustomer(currentCustomer);
         TempData["message"] = "Kunduppgifterna har uppdaterats!";
     }
     else {
         //FIXA FELMEDDELANDE
     }
     return RedirectToAction(actionName: "CustomerDetails", routeValues: new { id = currentId });
 }
Exemplo n.º 4
0
 public void DeleteCustomer(Customer customer)
 {
     context.Customers.Remove(customer);
     context.SaveChanges();
 }
Exemplo n.º 5
0
 public ActionResult Create()
 {
     Customer newCustomer = new Customer();
     return PartialView(newCustomer);
 }