public async Task <bool> Post(ResourceDescriptionModel description) { using (var entity = new CompanyBrokerResourceDescriptionEntities()) { if (description != null) { //-- Creates new resource based on the description var desc = new ResourceDescription() { ResourceId = description.ResourceId, Description = description.Description, CompanyId = description.CompanyId }; //-- adds it to the database entity.ResourceDescriptions.Add(desc); await entity.SaveChangesAsync(); //-- return(true); } else { return(false); } } }
public async Task <bool> Put(ResourceDescriptionModel description) { using (var entity = new CompanyBrokerResourceDescriptionEntities()) { if (description != null) { //-- Finds the resource var desc = entity.ResourceDescriptions.Where(a => a.ResourceId == description.ResourceId).Single <ResourceDescription>(); //-- Checks if it's null if (desc != null) { //-- Changes the fetched resource object desc.Description = description.Description; //-- Tells the entity framework, that we made a change on the fetched object. entity.Entry(desc).State = EntityState.Modified; //-- Trys to apply the changes to the database await entity.SaveChangesAsync(); //--- return(true); } else { return(false); } } else { return(false); } } }
public async Task <ResourceDescription> Get(int resourceId) { using (var entity = new CompanyBrokerResourceDescriptionEntities()) { return(await entity.ResourceDescriptions.FirstOrDefaultAsync(r => r.ResourceId == resourceId)); } }