public async Task <CallDto> UpdateCall(int id, CallDto callDto) { using (CellularCompanyContext db = new CellularCompanyContext()) { try { if (id != callDto.CallId) { return(null); } else { Call call = db.Calls.FirstOrDefault(c => c.CallId == id); if (call == null) { return(null); } else { call = callDto.ToModel(); db.Entry(call).State = System.Data.Entity.EntityState.Modified; await db.SaveChangesAsync(); return(call.ToDto()); } } } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } } }
public async Task <CallDto> CreateCall(CallDto callDto) { using (CellularCompanyContext db = new CellularCompanyContext()) { try { if (callDto == null) { return(null); } else { db.Calls.Add(callDto.ToModel()); await db.SaveChangesAsync(); return(callDto); } } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } } }