public async Task <IHttpActionResult> SaveLocalized(ODataActionParameters parameters)
        {
            if (!CheckPermission(WritePermission))
            {
                return(Unauthorized());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            string cultureCode = (string)parameters["cultureCode"];
            var    entity      = (EntityTypeContentBlock)parameters["entity"];

            if (entity.Id == Guid.Empty)
            {
                return(BadRequest());
            }
            string entityType = typeof(EntityTypeContentBlock).FullName;
            string entityId   = entity.Id.ToString();

            var localizedRecord = await localizablePropertyService.Value.FindOneAsync(x =>
                                                                                      x.CultureCode == cultureCode &&
                                                                                      x.EntityType == entityType &&
                                                                                      x.EntityId == entityId &&
                                                                                      x.Property == "BlockValues");

            if (localizedRecord == null)
            {
                localizedRecord = new LocalizableProperty
                {
                    CultureCode = cultureCode,
                    EntityType  = entityType,
                    EntityId    = entityId,
                    Property    = "BlockValues",
                    Value       = entity.BlockValues
                };
                await localizablePropertyService.Value.InsertAsync(localizedRecord);

                return(Ok());
            }
            else
            {
                localizedRecord.Value = entity.BlockValues;
                await localizablePropertyService.Value.UpdateAsync(localizedRecord);

                return(Ok());
            }
        }
Exemplo n.º 2
0
        public async Task <IHttpActionResult> SaveLocalized(ODataActionParameters parameters)
        {
            if (!CheckPermission(WritePermission))
            {
                return(Unauthorized());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            string cultureCode = (string)parameters["cultureCode"];
            var    entity      = (Region)parameters["entity"];

            if (entity.Id == 0)
            {
                return(BadRequest());
            }
            string entityType = typeof(Region).FullName;
            string entityId   = entity.Id.ToString();

            var localizedRecord = localizablePropertyService.Value.FindOne(cultureCode, entityType, entityId, "Name");

            if (localizedRecord == null)
            {
                localizedRecord = new LocalizableProperty
                {
                    CultureCode = cultureCode,
                    EntityType  = entityType,
                    EntityId    = entityId,
                    Property    = "Name",
                    Value       = entity.Name
                };
                await localizablePropertyService.Value.InsertAsync(localizedRecord);

                return(Ok());
            }
            else
            {
                localizedRecord.Value = entity.Name;
                await localizablePropertyService.Value.UpdateAsync(localizedRecord);

                return(Ok());
            }
        }