/// <summary> /// Maps a <see cref='Altask.Data.Model.TaskAlert'/> object to a <see cref='Altask.Data.Dto.TaskAlert'/> object. /// </summary> /// <param name="includeLogs">Indicates whether to load any logs associated with the object when mapping.</param> public static Altask.Data.Dto.TaskAlert ToDto(this Altask.Data.Model.TaskAlert entity, bool includeLogs = false) { var dto = new Altask.Data.Dto.TaskAlert(); dto.Id = entity.Id; dto.Active = entity.Active; dto.TaskId = entity.TaskId; dto.Name = entity.Name; dto.TimeN = entity.TimeN; dto.TimeUnit = entity.TimeUnit; dto.When = entity.When; dto.IfNot = entity.IfNot; dto.IfStatus = entity.IfStatus; dto.Metadata = JsonConvert.DeserializeObject("{Properties: []}"); if (!string.IsNullOrEmpty(entity.Metadata)) { try { XmlDocument doc = new XmlDocument(); doc.LoadXml(entity.Metadata); string json = Json.SerizlieXmlDocument(doc); dto.Metadata = JsonConvert.DeserializeObject(json); } catch (Exception) {} } dto.CreatedBy = entity.CreatedBy; dto.CreatedOn = entity.CreatedOn; dto.UpdatedBy = entity.UpdatedBy; dto.UpdatedOn = entity.UpdatedOn; dto.Logs = new List <Altask.Data.Dto.TaskAlertLog>(); if (includeLogs) { if (entity.Logs != null) { foreach (var item in entity.Logs) { dto.Logs.Add(item.ToDto()); } } } dto.Users = new List <Altask.Data.Dto.TaskAlertUser>(); if (entity.Users != null) { foreach (var item in entity.Users) { dto.Users.Add(item.ToDto()); } } return(dto); }
internal static void NotifyTaskAlertUpdate(Guid?clientId, Altask.Data.Dto.TaskAlert taskAlert) { if (!clientId.HasValue) { _context.Clients.All.notifyTaskAlertUpdate(new { taskAlert = taskAlert }); } else { SignalRConnection connection; if (_connections.TryGetValue(clientId.Value, out connection)) { _context.Clients.AllExcept(connection.ConnectionId).notifyTaskAlertUpdate(new { connection = connection, taskAlert = taskAlert }); } else { _context.Clients.All.notifyTaskAlertCreate(new { taskAlert = taskAlert }); } } }
/// <summary> /// Maps all the non-primary key and tracking properties of a <see cref='Altask.Data.Dto.TaskAlert'/> object to a <see cref='Altask.Data.Model.TaskAlert'/> object. /// </summary> public static Altask.Data.Model.TaskAlert FromDto(this Altask.Data.Model.TaskAlert model, Altask.Data.Dto.TaskAlert entity) { model.Active = entity.Active; model.TaskId = entity.TaskId; model.Name = entity.Name; model.TimeN = entity.TimeN; model.TimeUnit = entity.TimeUnit; model.When = entity.When; model.IfNot = entity.IfNot; model.IfStatus = entity.IfStatus; model.Metadata = string.Empty; try { model.Metadata = ((XmlDocument)JsonConvert.DeserializeXmlNode(entity.Metadata.ToString(), "Properties")).OuterXml; } catch (Exception) {} return(model); }