S
shapper
Hello,
I have a repository as follows:
public class BrandRepository : IBrandRepository {
public String Path { get; set; }
private XDocument context;
public BrandRepository() { } // BrandRepository
public BrandRepository(String path) {
this.Path = path;
this.context = XDocument.Load(this.Path);
} // BrandRepository
public Brand GetBrand(Guid id) {
Brand brand = (from b in context.Root.Elements("Brand")
where b.Element("BrandId").Value == id.ToString()
select new Brand {
Id = new Guid(b.Element("BrandId").Value),
Created = DateTime.Parse(b.Element
("Created").Value),
Name = b.Element("Name").Value,
Updated = DateTime.Parse(b.Element
("Updated").Value)
}).SingleOrDefault();
return brand;
} // GetBrand
}
And is used by ProductBinder which is fired when submitting a Create
Product form:
public class ProductBinder : IModelBinder {
private BrandRepository brandRepository = new BrandRepository
(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data/
Brands.xml"));
public object BindModel(ControllerContext controller,
ModelBindingContext binding) {
Brand b = brandRepository.GetBrand(new Guid((String)
binding.ValueProvider["Brand"].ConvertTo(typeof(String)))),
...
}
On debugging I did the following:
Created 3 Brands using the Brands form. No problem there.
Then I went to the Product form and I selected a Brand. I submitted
the form.
In ProductBinder Here the Brand b is null.
I check the Brands.xml file and the 3 Brands I created are there!
I check the GetBrand method and the Id received is correct but it
returns a null Brand.
Then I stop debugging it and restart it again.
Now I don't have any error!
I am completely lost.
It might to have something to do with the XML loading?
Does anyone has any idea why this happens?
Thanks,
Miguel
I have a repository as follows:
public class BrandRepository : IBrandRepository {
public String Path { get; set; }
private XDocument context;
public BrandRepository() { } // BrandRepository
public BrandRepository(String path) {
this.Path = path;
this.context = XDocument.Load(this.Path);
} // BrandRepository
public Brand GetBrand(Guid id) {
Brand brand = (from b in context.Root.Elements("Brand")
where b.Element("BrandId").Value == id.ToString()
select new Brand {
Id = new Guid(b.Element("BrandId").Value),
Created = DateTime.Parse(b.Element
("Created").Value),
Name = b.Element("Name").Value,
Updated = DateTime.Parse(b.Element
("Updated").Value)
}).SingleOrDefault();
return brand;
} // GetBrand
}
And is used by ProductBinder which is fired when submitting a Create
Product form:
public class ProductBinder : IModelBinder {
private BrandRepository brandRepository = new BrandRepository
(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data/
Brands.xml"));
public object BindModel(ControllerContext controller,
ModelBindingContext binding) {
Brand b = brandRepository.GetBrand(new Guid((String)
binding.ValueProvider["Brand"].ConvertTo(typeof(String)))),
...
}
On debugging I did the following:
Created 3 Brands using the Brands form. No problem there.
Then I went to the Product form and I selected a Brand. I submitted
the form.
In ProductBinder Here the Brand b is null.
I check the Brands.xml file and the 3 Brands I created are there!
I check the GetBrand method and the Id received is correct but it
returns a null Brand.
Then I stop debugging it and restart it again.
Now I don't have any error!
I am completely lost.
It might to have something to do with the XML loading?
Does anyone has any idea why this happens?
Thanks,
Miguel