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 -->>"); } }