Encja z Complex Type - wstawianie i edytowanie

0

Hej,
Pisałam niedawno o problemie z value object, dzięki wielkie za pomoc! Teraz jednak dalej mam problem z tymi Complex Type.
Wszystko na stronie ładnie mi się wyświetla, za pomocą inicjalizatora mi się wpisują dane do bazy, jednak kiedy chcę edytować, bądź stworzyć nową encję budynek, to tworzy mi ją bez adresu. Przypuszczam, że muszę go gdzieś przekazać albo stworzyć jako część tej encji, ale nie mam pojęcia gdzie to zrobić. Bardzo proszę o pomoc.

Klasy:

Edit z kontrolera:

    // GET: Buildings/Edit/5
    public ActionResult Edit(int? id)
    {
        if (id == null)
        {
            return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        }

        Building building = repository.Single((int)id);

        BuildingCreateEditViewModel editViewModel =
        Mapper.Map<Building, BuildingCreateEditViewModel>(building);


      


        if (building == null)
        {
            return HttpNotFound();
        }

        return View(editViewModel);
    }

    // POST: Buildings/Edit/5
    // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
    * more details see http:*go.microsoft.com/fwlink/?LinkId=317598.
    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Edit([Bind(Include = "ID,DepartmentName,Address")] Building building, BuildingCreateEditViewModel editViewModel)
    {
        try
        {
            if (ModelState.IsValid)
            {

                repository.Update(building);
                repository.SaveChanges();
                return RedirectToAction("Index");
            }
        }
        catch (DataException /* dex */)
        {
            //Log the error (uncomment dex variable name and add a line here to write a log.
            ModelState.AddModelError("",
                "Unable to save changes. Try again, and if the problem persists see your system administrator.");
        }

        return View(editViewModel);
    }

Building:

public String DepartmentName { get; set; }
public AddressData Address { get; set; }

    public virtual ICollection<Floor> Floors { get; set; }


   public Building()
   { 
       Address=new AddressData();
   }

Address:

public class AddressData : ValueObject<AddressData>
{

    public String StreetWithNumber { get; private set; }
    public String City { get; private set; }
    public String Region { get; private set; }
    public String Country { get; private set; }
    public String PostalCode { get; private set; }


    public AddressData ()
    {
        

    }
    public AddressData(String street, String city, String region, String country, String postalCode)
    {
        this.StreetWithNumber = street;
        this.City = city;
        this.Region = region;
        this.Country = country;
        this.PostalCode = postalCode;


    }
0

problem rozwiązany.

0

To podziel sie z nami rozwiazaniem dla potomnych ;)

1 użytkowników online, w tym zalogowanych: 0, gości: 1