/// <summary>
        /// Updates an existing relation type.
        /// </summary>
        /// <param name="relationType">The relation type to update.</param>
        /// <returns>A display object containing the updated relation type.</returns>
        public ActionResult <RelationTypeDisplay?> PostSave(RelationTypeSave relationType)
        {
            var relationTypePersisted = _relationService.GetRelationTypeById(relationType.Key);

            if (relationTypePersisted == null)
            {
                return(ValidationProblem("Relation type does not exist"));
            }

            _umbracoMapper.Map(relationType, relationTypePersisted);

            try
            {
                _relationService.Save(relationTypePersisted);
                var display = _umbracoMapper.Map <RelationTypeDisplay>(relationTypePersisted);
                display?.AddSuccessNotification("Relation type saved", "");

                return(display);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error saving relation type with {Id}", relationType.Id);
                return(ValidationProblem("Something went wrong when saving the relation type"));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Updates an existing relation type.
        /// </summary>
        /// <param name="relationType">The relation type to update.</param>
        /// <returns>A display object containing the updated relation type.</returns>
        public RelationTypeDisplay PostSave(RelationTypeSave relationType)
        {
            var relationTypePersisted = Services.RelationService.GetRelationTypeById(relationType.Key);

            if (relationTypePersisted == null)
            {
                throw new HttpResponseException(Request.CreateNotificationValidationErrorResponse("Relation type does not exist"));
            }

            Mapper.Map(relationType, relationTypePersisted);

            try
            {
                Services.RelationService.Save(relationTypePersisted);
                var display = Mapper.Map <RelationTypeDisplay>(relationTypePersisted);
                display.AddSuccessNotification("Relation type saved", "");

                return(display);
            }
            catch (Exception ex)
            {
                Logger.Error <object>(GetType(), ex, "Error saving relation type with {Id}", relationType.Id);
                throw new HttpResponseException(Request.CreateNotificationValidationErrorResponse("Something went wrong when saving the relation type"));
            }
        }
 // Umbraco.Code.MapAll -CreateDate -UpdateDate -DeleteDate
 private static void Map(RelationTypeSave source, IRelationType target, MapperContext context)
 {
     target.Alias           = source.Alias;
     target.ChildObjectType = source.ChildObjectType;
     target.Id = source.Id.TryConvertTo <int>().Result;
     target.IsBidirectional  = source.IsBidirectional;
     target.Key              = source.Key;
     target.Name             = source.Name;
     target.ParentObjectType = source.ParentObjectType;
 }
Esempio n. 4
0
        /// <summary>
        /// Creates a new relation type.
        /// </summary>
        /// <param name="relationType">The relation type to create.</param>
        /// <returns>A <see cref="HttpResponseMessage"/> containing the persisted relation type's ID.</returns>
        public HttpResponseMessage PostCreate(RelationTypeSave relationType)
        {
            var relationTypePersisted = new RelationType(relationType.Name, relationType.Name.ToSafeAlias(true), relationType.IsBidirectional, relationType.ChildObjectType, relationType.ParentObjectType);

            try
            {
                Services.RelationService.Save(relationTypePersisted);

                return(Request.CreateResponse(HttpStatusCode.OK, relationTypePersisted.Id));
            }
            catch (Exception ex)
            {
                Logger.Error <string>(GetType(), ex, "Error creating relation type with {Name}", relationType.Name);
                return(Request.CreateNotificationValidationErrorResponse("Error creating relation type."));
            }
        }
        /// <summary>
        /// Creates a new relation type.
        /// </summary>
        /// <param name="relationType">The relation type to create.</param>
        /// <returns>A <see cref="HttpResponseMessage"/> containing the persisted relation type's ID.</returns>
        public ActionResult <int> PostCreate(RelationTypeSave relationType)
        {
            var relationTypePersisted = new RelationType(
                relationType.Name,
                relationType.Name.ToSafeAlias(_shortStringHelper, true),
                relationType.IsBidirectional,
                relationType.ParentObjectType,
                relationType.ChildObjectType);

            try
            {
                _relationService.Save(relationTypePersisted);

                return(relationTypePersisted.Id);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error creating relation type with {Name}", relationType.Name);
                return(ValidationProblem("Error creating relation type."));
            }
        }