private static void InsertOrUpdate(List <Tickets> tickets, uint uid, string fileName) { var ticketsId = tickets.Select(x => x.IncidentID); using (var context = new TicketDbEntities()) { var existTickes = context.Tickets.Where(x => ticketsId.Contains(x.IncidentID)); if (existTickes.Any()) { foreach (var item in existTickes) { var ticket = tickets.FirstOrDefault(x => x.IncidentID == item.IncidentID); var ticketToUpdate = context.Tickets.FirstOrDefault(x => x.IncidentID == item.IncidentID); ticketToUpdate.ResolutionCode = ticket.ResolutionCode; ticketToUpdate.ResolutionDesc = ticket.ResolutionDesc; ticketToUpdate.ResolveUserID = ticket.ResolveUserID; ticketToUpdate.TicketStatus = ticket.TicketStatus; ticketToUpdate.ResolveTime = ticket.ResolveTime; } context.SaveChanges(); tickets.RemoveAll(x => existTickes.Select(y => x.IncidentID).Contains(x.IncidentID)); } if (tickets.Any()) { context.Tickets.AddRange(tickets); var logMail = context.LogEmail.FirstOrDefault(x => x.UidMail == uid); logMail.IsLoad = true; logMail.FIlesName += fileName + ", "; context.SaveChanges(); } } }
private static void saveLogMail(LogEmail logMail) { try { using (var context = new TicketDbEntities()) { context.LogEmail.Add(logMail); context.SaveChanges(); } } catch (Exception ex) { _log.LogError(ex.Message, "saveLogMail<<-- Guarda en Bd los emails -->>"); } }
private static uint GetLastUid() { try { using (var context = new TicketDbEntities()) { var mailsUids = context.LogEmail.Max(p => p.UidMail); return((uint)mailsUids); } } catch (Exception ex) { _log.LogError(ex.Message, "GetLastUid <<--Obtiene el ultimo uid del email registrado -->>"); return(0); } }
private static List <uint> GetUidEmail(List <uint> uids) { try { using (var context = new TicketDbEntities()) { var ids = uids.ConvertAll(i => (int)i); var mailsUids = context.LogEmail.Where(x => ids.Contains(x.UidMail)).Select(x => x.UidMail).ToList(); mailsUids.ForEach(x => ids.Remove(x)); return(ids.ConvertAll(i => (uint)i)); } } catch (Exception ex) { _log.LogError(ex.Message, "GetUidEmail<<-- Elimina los emails leidos que ya han sido procesados -->>"); return(uids); } }