c# - How to update an entity using Entity Framework from Business Layer? -


i web application structured 3 layers, controller, business logic , repository.

from bl layer updating entity following code. can see updating property property.

i know if there better way it, removing manual mapping.

---------------------- controller

    public ihttpactionresult put(int id, devicedto dto)     {         gadevice device = mapper.map<gadevice>(dto);         devicebll.update(id, device);         return ok();     } 

---------------------- bl

    public void update(int id, gadevice entity)     {         bool hasvalidid = getbyid(id) != null ? true : false;         if (hasvalidid == true)         {             gadevice device = devicerepo.getbyid(id);             device.cannotifypc = entity.cannotifypc; // not sure here             device.cannotifyprinter = entity.cannotifyprinter;             device.locationid = entity.locationid;             device.name = entity.name;             device.note = entity.note;             device.operativefromtime = entity.operativefromtime;             device.operativetotime = entity.operativetotime;             devicerepo.update(device );             devicerepo.save();         } 

---------------- repository

    public void update(gadevice entity)     {         context.entry(entity).state = entitystate.modified;     } 

what saving changes made context in update()? otherwise, code in save() do?

public void update(gadevice entity) {     context.entry(entity).state = entitystate.modified;     context.savechanges(); } 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -