public async Task <LineDto> UpdateLine(LineDto line, string clientId)
        {
            using (CellularCompanyContext db = new CellularCompanyContext())
            {
                try
                {
                    if (line != null)
                    {
                        if (line.ClientId == clientId)
                        {
                            LineEntity entity = line.ToModel();
                            entity.LineId = line.LineId;
                            db.Lines.Attach(entity);
                            foreach (var propName in db.Entry(entity).CurrentValues.PropertyNames)
                            {
                                if (propName != "LineId")
                                {
                                    db.Entry(entity).Property(propName).IsModified = true;
                                }
                            }
                            await db.SaveChangesAsync();

                            return(entity.ToDto());
                        }
                        return(null);
                    }
                    return(null);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    return(null);
                }
            }
        }
Example #2
0
        public async Task <LineDto> UpdateLine(int id, LineDto lineDto)
        {
            using (CellularCompanyContext db = new CellularCompanyContext())
            {
                try
                {
                    if (lineDto != null && id != 0 && CheckIfLineNumberAlreadyExist(lineDto.Number))
                    {
                        lineDto.LineId = id;
                        Line entity = lineDto.ToModel();
                        db.Lines.Attach(entity);
                        foreach (var propName in db.Entry(entity).CurrentValues.PropertyNames)
                        {
                            if (propName != nameof(entity.LineId))
                            {
                                db.Entry(entity).Property(propName).IsModified = true;
                            }
                        }
                        await db.SaveChangesAsync();

                        return(entity.ToDto());
                    }
                    return(null);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    return(null);
                }
            }
        }
Example #3
0
        public async Task <LineDto> CreateLine(LineDto lineDto, SelectedNumberDto selectedNumberDto)
        {
            using (CellularCompanyContext db = new CellularCompanyContext())
            {
                try
                {
                    if (lineDto == null)
                    {
                        return(null);
                    }
                    else
                    {
                        lineDto.SelectedNumbers = selectedNumberDto;
                        db.Lines.Add(lineDto.ToModel());
                        await db.SaveChangesAsync();

                        return(lineDto);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    return(null);
                }
            }
        }
        public LinesViewModel(INavigationService navigationService)
        {
            _navigationService = navigationService;
            Line = new LineModel();

            var task = Task.Factory.StartNew(() => GetLines());

            Lines = new ObservableCollection <LineModel>(task.Result.Result);

            LineDto   dto   = server.GetLineAsync(Line.Number).Result;
            LineModel model = dto.ToModel();

            dto.Package = model.Package.ToDto();
        }
        public async Task <LineDto> CreateLine(LineDto line)
        {
            using (CellularCompanyContext db = new CellularCompanyContext())
            {
                try
                {
                    if (line != null)
                    {
                        LineEntity entity = line.ToModel();
                        db.Lines.Add(entity);
                        await db.SaveChangesAsync();

                        return(entity.ToDto());
                    }
                    return(null);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    return(null);
                }
            }
        }
Example #6
0
        public async Task <LineDto> AddLineEntity(LineDto line, SelectedNumbersDto selectedNumbers)
        {
            using (CellularCompanyContext db = new CellularCompanyContext())
            {
                try
                {
                    if (line != null && CheckIfLineNumberAlreadyExist(line.Number))
                    {
                        line.SelectedNumber = selectedNumbers;
                        LineEntity lineEntity = line.ToModel();
                        db.Lines.Add(lineEntity);
                        await db.SaveChangesAsync();

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