Example #1
0
        private async Task <int> AddSerials(List <SerialsDB> serials, int id)
        {
            int adds     = 0;
            int idSerial = _invoicesService.GetLastIdInvoiceSerials().Result;

            idSerial++;
            foreach (var s in serials)
            {
                var existingSerial = _serialService.GetSerialBySerial(s.Serial);
                var aux            = existingSerial.Result != null ? existingSerial.Result.Id : 0;
                if (aux != 0)
                {
                    var newItem = new InvoiceSerials
                    {
                        Id        = idSerial,
                        Serial    = s.Serial.ToString(),
                        InvoiceID = id
                    };
                    idSerial++;

                    var res = await _invoicesService.UpdateInvoiceSerialsTable(newItem);

                    adds += res;
                }
            }
            return(adds);
        }
Example #2
0
        public async Task <SerialsDB> Add(string newSerial)
        {
            var existingSerial = _serialService.GetSerialBySerial(newSerial);

            if (existingSerial.Id != 0)
            {
                int id = _serialService.GetLastIdSerial().Result;

                var serial = new SerialsDB
                {
                    Id     = id + 1,
                    Serial = newSerial
                };

                var result = await _context.Serials.AddAsync(serial);

                return(result.Entity);
            }

            return(new SerialsDB {
            });
        }