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

            dto.Id          = entity.Id;
            dto.UserId      = entity.UserId;
            dto.Type        = entity.Type;
            dto.Description = entity.Description;
            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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Maps all the non-primary key and tracking properties of a <see cref='Altask.Data.Dto.UserLog'/> object to a <see cref='Altask.Data.Model.UserLog'/> object.
        /// </summary>
        public static Altask.Data.Model.UserLog FromDto(this Altask.Data.Model.UserLog model, Altask.Data.Dto.UserLog entity)
        {
            model.UserId      = entity.UserId;
            model.Type        = entity.Type;
            model.Description = entity.Description;
            model.Metadata    = string.Empty;

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

            return(model);
        }