Esempio n. 1
0
 public ActionResult EditAddress(Guid rowguid)
 {
     var address = new AddressViewModel();
     var customeraddress = repository.CustomerAddresses.SingleOrDefault(x => x.rowguid == rowguid);
     if (customeraddress == null) return RedirectToAction("Addresses");
     address.AddressType = customeraddress.AddressType;
     address.Address = customeraddress.Address;
     address.rowguid = rowguid;
     return View(address);
 }
Esempio n. 2
0
 public ActionResult EditAddress(AddressViewModel model)
 {
     if (ModelState.IsValid)
     {
         var address = repository.Addresses.SingleOrDefault(x => x.AddressID == model.Address.AddressID) ?? model.Address;
         if (address.CustomerAddresses == null)
         {
             var customer = repository.Customers.SingleOrDefault(x => x.EmailAddress == this.HttpContext.User.Identity.Name);//x.CustomerID == 29559);  //EmailAddress == this.HttpContext.User.Identity.Name
             if (customer == null) return RedirectToAction("LogOn", "Account");
             model.Address.CustomerAddresses = new Collection<CustomerAddress>();
             model.Address.CustomerAddresses.Add(new CustomerAddress()
                                                     {
                                                         AddressID = model.Address.AddressID,
                                                         CustomerID = customer.CustomerID,
                                                         AddressType = model.AddressType
                                                     });
         }
         else
         {
             var customeraddress = address.CustomerAddresses.SingleOrDefault(x => x.rowguid == model.rowguid);
             if (customeraddress !=null) customeraddress.AddressType = model.AddressType;
             repository.Save(customeraddress);
         }
         repository.Save(model.Address);
         return RedirectToAction("Addresses");
     }
     return View(model);
 }