Beispiel #1
0
        public async Task Scan()
        {
            try
            {
                QrHandler qr  = new QrHandler();
                string    res = await qr.Scan();

                res = res.Replace("<Part>", "");
                Part p = await PartKeeper.GetByToken(res);

                if (p == null)
                {
                    DependencyService.Get <IToaster>().ShortAlert($"Część o kodzie {res} nie została znaleziona!");
                }
                else
                {
                    PartUsage pu = new PartUsage
                    {
                        PartId       = p.PartId,
                        Name         = p.Name,
                        Symbol       = p.Symbol,
                        ProducerId   = p.ProducerId,
                        ProducerName = p.ProducerName,
                        Description  = p.Description,
                        Image        = p.Image,
                        Amount       = 1
                    };
                    Items.Add(pu);
                }
            }
            catch (Exception ex)
            {
                DependencyService.Get <IToaster>().ShortAlert($"Error: {ex.Message}");
            }
        }
Beispiel #2
0
        public List <PartUsage> CreatePartUsage(PartUsage partUsage)
        {
            using TinyCollegeContext _context = new TinyCollegeContext(_builder.Options);

            _context.Add(partUsage);
            _context.SaveChanges();
            return(_context.PartUsages.Where(x => x.PartUsageId == _context.PartUsages.Max(x => x.PartUsageId)).ToList());
        }
Beispiel #3
0
        public List <PartUsage> EditPartUsage(PartUsage partUsage)
        {
            using TinyCollegeContext _context = new TinyCollegeContext(_builder.Options);
            var tmpPartUsage = _context.PartUsages.First(x => x.PartUsageId == partUsage.PartUsageId);

            _context.Entry(tmpPartUsage).CurrentValues.SetValues(partUsage);
            _context.SaveChanges();
            return(_context.PartUsages.Where(x => x.PartUsageId == partUsage.PartUsageId).ToList());
        }
Beispiel #4
0
        public List <PartUsage> DeletePartUsage(PartUsage partUsage)
        {
            using TinyCollegeContext _context = new TinyCollegeContext(_builder.Options);

            try
            {
                _context.PartUsages.Attach(partUsage);
                _context.PartUsages.Remove(partUsage);
                _context.SaveChanges();
            }
            catch (Exception e)
            {
                // ignored
            }

            return(_context.PartUsages.ToList());
        }
Beispiel #5
0
 public async Task Update()
 {
     if (PartsPageViewModel.SelectedItems.Count > 0)
     {
         //add new item and clear selectedItems
         foreach (Part p in PartsPageViewModel.SelectedItems)
         {
             PartUsage pu = new PartUsage
             {
                 PartId       = p.PartId,
                 Name         = p.Name,
                 Symbol       = p.Symbol,
                 ProducerId   = p.ProducerId,
                 ProducerName = p.ProducerName,
                 Description  = p.Description,
                 Image        = p.Image,
                 Amount       = 1
             };
             Items.Add(pu);
         }
         //OnPropertyChanged(nameof(Items));
         PartsPageViewModel.SelectedItems.Clear();
     }
 }