コード例 #1
0
        public async Task <SelectedNumbersDto> UpdateSelectedNumber(SelectedNumbersDto number)
        {
            using (CellularCompanyContext db = new CellularCompanyContext())
            {
                try
                {
                    if (number != null)
                    {
                        SelectedNumbersEntity entity = number.ToModel();
                        entity.Id = number.Id;
                        db.SelectedNumbers.Attach(entity);
                        foreach (var propName in db.Entry(entity).CurrentValues.PropertyNames)
                        {
                            if (propName != "Id")
                            {
                                db.Entry(entity).Property(propName).IsModified = true;
                            }
                        }
                        await db.SaveChangesAsync();

                        return(entity.ToDto());
                    }
                    return(null);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    return(null);
                }
            }
        }
コード例 #2
0
ファイル: LineRepository.cs プロジェクト: idoda1307/HisRepo1
        public IEnumerable <string> GetLineSelectedNumbers(int lineId)
        {
            using (CellularCompanyContext db = new CellularCompanyContext())
            {
                try
                {
                    List <string>         list   = new List <string>();
                    SelectedNumbersEntity entity = db.SelectedNumbers.Where(s => s.Line.LineId == lineId).FirstOrDefault();
                    foreach (var propName in db.Entry(entity).CurrentValues.PropertyNames)
                    {
                        if (propName.EndsWith("Number"))
                        {
                            if (db.Entry(entity).Property(propName).CurrentValue != null)
                            {
                                list.Add(db.Entry(entity).Property(propName).CurrentValue.ToString());
                            }
                        }
                    }

                    return(list);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    return(null);
                }
            }
        }
コード例 #3
0
 public static SelectedNumbersDto ToDto(this SelectedNumbersEntity numbers)
 {
     return(new SelectedNumbersDto()
     {
         FirstNumber = numbers.FirstNumber,
         Id = numbers.Id,
         SecondNumber = numbers.SecondNumber,
         ThirdNumber = numbers.ThirdNumber,
         //PackageIncludes=numbers.PackageIncludes.Select(p=>p.ToDto()).ToList()
     });
 }
コード例 #4
0
        public async Task <SelectedNumbersDto> CreateSelectedNumber(SelectedNumbersDto number)
        {
            using (CellularCompanyContext db = new CellularCompanyContext())
            {
                try
                {
                    if (number != null)
                    {
                        SelectedNumbersEntity entity = number.ToModel();
                        db.SelectedNumbers.Add(entity);
                        await db.SaveChangesAsync();

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