コード例 #1
0
        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);
                }
            }
        }
コード例 #2
0
        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);
                }
            }
        }