Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
My repositoty code:
public MedicalGroupModel Add(MedicalGroupModel model)
       {
           Data.MedicalGroup MedicalgroupEF = new Data.MedicalGroup();

           MedicalgroupEF.MedicalGroupName = model.MedicalGroupName;
           MedicalgroupEF.AddressId = model.AddressId;
           MedicalgroupEF.ContactId = model.ContactId;

           int id = 0;
           using (Data.RxMedicaDBEntities content = new Data.RxMedicaDBEntities())
           {
               content.AddToMedicalGroups(MedicalgroupEF);
               content.SaveChanges();

               id = MedicalgroupEF.MedicalGroupId;
           }
           model = Get(id);
           return model;
       }


controller:
XML
public ActionResult Add([DataSourceRequest] DataSourceRequest request, MedicalGroupModel model)
       {
           List<RxMedica.Model.MedicalGroupModel> medicalgroupList = new List<MedicalGroupModel>();
           medicalgroupList = RxMedica.Configuration.ServiceLocator.MedicalgroupHandler.Add(model);

           return Json(medicalgroupList.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
       }
Posted
Updated 11-Jun-15 2:25am
v5
Comments
John C Rayan 10-Jun-15 8:03am    
Where do you get the error? More details would be better.
Dave Kreskowiak 10-Jun-15 8:12am    
Don't you think it would be important if you told us what the error was?
siva Prasad Paruchuri 10-Jun-15 8:15am    
1.'RxMedica.Data.RxMedicaDBEntities': type used in a using statement must be implicitly convertible to 'System.IDisposable'
2.The name 'Medicalgroupname','AddressId','ContactId' does not exist in the current context
Krunal Rohit 16-Jun-15 2:36am    
Can share the list of namespaces you're using ?

-KR

Your model is a list of MedicalGroupModel objects

List<MedicalGroupModel> medicalgroupmodel = new List<MedicalGroupModel>();


but when you add to it you are adding a class of type MedicalGroup

C#
var newgroup = new MedicalGroup();
{
    Medicalgroupname = newgroup.MedicalGroupName;
    AddressId = newgroup.AddressId;
    ContactId = newgroup.ContactId;
}


Maybe the AddressId and ContactId etc properties are on the MedicalGroupModel class instead? ie did you mean this

C#
var newgroup = new MedicalGroupModel();
{
    Medicalgroupname = newgroup.MedicalGroupName;
    AddressId = newgroup.AddressId;
    ContactId = newgroup.ContactId;
}


As for the IDisposable error, if you want to use something in a "using" block it must implement IDisposible, so if your RxMedicaDBEntities doesn't then amend it so it does.

C#
public class RxMedicaDBEntities : IDisposable
 
Share this answer
 
If you're getting the using error with a EF DbContext, its usually because you didn't add the EntityFramework to the project that's using the context.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900