public async Task <ICollection <RepairDocument> > AddMultipleRepairDocumentsAsync(ICollection <RepairDocument> documents) { await _context.RepairDocuments.AddRangeAsync(documents); await _context.SaveChangesAsync(); return(documents); }
public async Task <Link> AddLinkAsync(Link link) { var repairDevice = await _context.RepairDevices.FirstOrDefaultAsync(dev => dev.Id == link.RepairDeviceId); if (repairDevice == null) { return(null); } link.RepairDevice = repairDevice; await _context.Links.AddAsync(link); await _context.SaveChangesAsync(); return(link); }
public async Task <WorkDuration> AddOrUpdateWorkDurationAsync(WorkDuration duration) { var device = await _repairContext.UserDevices .Include(u => u.Durations) .FirstOrDefaultAsync(u => u.Id == duration.UserDeviceId); if (device == null) { return(null); } WorkDuration newDuration = null; if (device.Durations != null && device.Durations.Any()) { newDuration = device.Durations.FirstOrDefault(d => d.Type == duration.Type); } if (newDuration != null) { _repairContext.Entry(newDuration).State = EntityState.Detached; newDuration.UserDeviceId = duration.UserDeviceId; newDuration.Device = duration.Device; newDuration.TimeTaken = duration.TimeTaken; newDuration.Type = duration.Type; _repairContext.Entry(newDuration).State = EntityState.Modified; } else { newDuration = duration; await _repairContext.AddAsync(newDuration); } await _repairContext.SaveChangesAsync(); return(newDuration); }