Exemple #1
0
        public async Task ModifyResourceItem(ResourceModifyRequestModel model, CancellationToken cancel)
        {
            bool addMode = false;
            var  pointer = await collection.FindAsync(m => m.ResourceKey == model.Key);

            var head = await pointer.FirstOrDefaultAsync();

            if (head == null)
            {
                head    = BuildHead(model.Key);
                addMode = true;
            }
            var item = head.ResourceItems.FirstOrDefault(m => m.Culture == model.Culture && m.Application == model.Application);

            if (item == null)
            {
                head.ResourceItems.Add(BuildItem(model.Culture, model.Value, model.Application));
            }
            else
            {
                item.Value = model.Value;
            }
            if (addMode)
            {
                await collection.InsertOneAsync(head);
            }
            else
            {
                await collection.ReplaceOneAsync(m => m.ResourceKey == model.Key, head);
            }
        }
Exemple #2
0
        public async Task <IActionResult> ManageLocalization([FromBody] ResourceModifyRequestModel model, CancellationToken cancel)
        {
            try
            {
                await managementService.ModifyResourceItem(model, cancel);

                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest());
            }
        }