Beispiel #1
0
        public async Task <PackageIncludeDto> UpdatePackageInclude(int id, PackageIncludeDto packageIncludeDto)
        {
            using (CellularCompanyContext db = new CellularCompanyContext())
            {
                try
                {
                    if (id != packageIncludeDto.PackageIncludeId)
                    {
                        return(null);
                    }
                    else
                    {
                        PackageInclude pi = db.PackageIncludes.FirstOrDefault(p => p.PackageIncludeId == id);
                        if (pi == null)
                        {
                            return(null);
                        }
                        else
                        {
                            pi = packageIncludeDto.ToModel();
                            db.Entry(pi).State = System.Data.Entity.EntityState.Modified;
                            await db.SaveChangesAsync();

                            return(pi.ToDto());
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    return(null);
                }
            }
        }
Beispiel #2
0
        public async Task <PackageIncludeDto> CreatePackageInclude(PackageIncludeDto packageIncludeDto)
        {
            using (CellularCompanyContext db = new CellularCompanyContext())
            {
                try
                {
                    if (packageIncludeDto == null)
                    {
                        return(null);
                    }
                    else
                    {
                        db.PackageIncludes.Add(packageIncludeDto.ToModel());
                        await db.SaveChangesAsync();

                        return(packageIncludeDto);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    return(null);
                }
            }
        }