Example #1
0
        /// <summary>
        /// Maps a <see cref='Altask.Data.Model.TaskAlertLog'/> object to a <see cref='Altask.Data.Dto.TaskAlertLog'/> object.
        /// </summary>
        /// <param name="includeLogs">Indicates whether to load any logs associated with the object when mapping.</param>
        public static Altask.Data.Dto.TaskAlertLog ToDto(this Altask.Data.Model.TaskAlertLog entity, bool includeLogs = false)
        {
            var dto = new Altask.Data.Dto.TaskAlertLog();

            dto.Id          = entity.Id;
            dto.TaskAlertId = entity.TaskAlertId;
            dto.UserId      = entity.UserId;
            dto.Type        = entity.Type;
            dto.Description = entity.Description;
            dto.AlertDate   = entity.AlertDate;
            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;

            if (entity.User != null)
            {
                dto.User = entity.User.ToDto();
            }

            return(dto);
        }
Example #2
0
        /// <summary>
        /// Maps all the non-primary key and tracking properties of a <see cref='Altask.Data.Dto.TaskAlertLog'/> object to a <see cref='Altask.Data.Model.TaskAlertLog'/> object.
        /// </summary>
        public static Altask.Data.Model.TaskAlertLog FromDto(this Altask.Data.Model.TaskAlertLog model, Altask.Data.Dto.TaskAlertLog entity)
        {
            model.TaskAlertId = entity.TaskAlertId;
            model.UserId      = entity.UserId;
            model.Type        = entity.Type;
            model.Description = entity.Description;
            model.AlertDate   = entity.AlertDate;
            model.Metadata    = string.Empty;

            try {
                model.Metadata = ((XmlDocument)JsonConvert.DeserializeXmlNode(entity.Metadata.ToString(), "Properties")).OuterXml;
            } catch (Exception) {}

            return(model);
        }