Exemplo n.º 1
0
        public void CreateReferenceAndExecuteUpdate_Passing(IEnumerable <string> arguments, IEnumerable <object> message)
        {
            List <object> e = new List <object>();

            TemplateUpdateModel u = null;

            if (arguments.Count() == 0)
            {
                u = new TemplateUpdateModel();
            }
            else
            {
                u = new TemplateUpdateModel(arguments);
            }

            u.UpdateMessage += delegate(object o)
            {
                e.Add(o);
            };

            u.Update();

            Assert.NotNull(u);
            Assert.True(e.SequenceEqual(message));
        }
Exemplo n.º 2
0
        public void CreateReferenceAndGetModel_Passing()
        {
            List <string> a = new List <string>()
            {
                "TemplateUpdateModelLib.json"
            };

            testArguments.ForEach(e => a.Add(e));

            TemplateUpdateModel u = new TemplateUpdateModel(a);

            Assert.NotNull(u);
            Assert.Equal("Template".ToLower(), u.Model);
        }
Exemplo n.º 3
0
        public void CreateReference_Failing(string file, IEnumerable <string> arguments, RaGae.ArgumentLib.MarshalerLib.ErrorCode errorCode, string message)
        {
            List <string> a = new List <string>()
            {
                file
            };

            arguments.ToList().ForEach(e => a.Add(e));

            TemplateUpdateModel u = null;

            ArgumentException ex = Assert.Throws <ArgumentException>(() => u = new TemplateUpdateModel(a));

            Assert.Null(u);
            Assert.Equal(errorCode, ex.ErrorCode);
            Assert.Equal(message, ex.Message);
            Assert.Equal(message, ex.ErrorMessage());
        }
        public async Task Update(TemplateUpdateModel model)
        {
            var table     = tableClient.GetTableReference(TableName);
            var container = blobClient.GetContainerReference(options.Container);

            await Task.WhenAll(table.CreateIfNotExistsAsync(), container.CreateIfNotExistsAsync());

            var template = new Template(model.Name, model.Language);

            var entity = await table.ExecuteAsync(
                TableOperation.Retrieve(template.PartitionKey, template.RowKey));

            if (entity.Result == null)
            {
                throw new ArgumentException($"A template {template.PartitionKey}:{template.RowKey} does not exists.");
            }

            var blob = container.GetBlockBlobReference($"{template.PartitionKey}/{template.RowKey}/{template.RowKey}.cshtml");

            await blob.UploadFromStreamAsync(model.Template.OpenReadStream());
        }
Exemplo n.º 5
0
        public void CreateReference_Passing(string file, IEnumerable <string> arguments)
        {
            List <string> a = new List <string>()
            {
                file
            };

            arguments.ToList().ForEach(e => a.Add(e));

            TemplateUpdateModel u = null;

            if (a.Count() == 1)
            {
                u = new TemplateUpdateModel();
            }
            else
            {
                u = new TemplateUpdateModel(a);
            }

            Assert.NotNull(u);
        }
Exemplo n.º 6
0
        public void CreateReferenceAndExecuteAfterUpdate_Passing()
        {
            List <object> e = new List <object>();
            List <string> a = new List <string>()
            {
                "TemplateUpdateModelLib.json"
            };

            testArguments.ForEach(e => a.Add(e));

            TemplateUpdateModel u = new TemplateUpdateModel(a);

            u.UpdateMessage += delegate(object o)
            {
                e.Add(o);
            };

            u.AfterUpdate();

            Assert.NotNull(u);
            Assert.True(e.Count == 1);
            Assert.Equal(TemplateResource.AfterUpdate, e.ElementAt(0));
        }
 public Task Update(TemplateUpdateModel model)
 {
     return(templatesRepository.Update(model));
 }
Exemplo n.º 8
0
        public async Task <IActionResult> Update(TemplateUpdateModel model)
        {
            await templatesService.Update(model);

            return(Ok());
        }
Exemplo n.º 9
0
        public void Update(ApiCall call)
        {
            var formResult = Kooboo.Lib.NETMultiplePart.FormReader.ReadForm(call.Context.Request.PostData);

            TemplateUpdateModel update = new TemplateUpdateModel();

            update.UserId = call.Context.User.Id;

            if (formResult.FormData.ContainsKey("id"))
            {
                string strid = formResult.FormData["id"];
                Guid   id;
                if (System.Guid.TryParse(strid, out id))
                {
                    update.Id = id;
                }
                else
                {
                    throw new Exception(Data.Language.Hardcoded.GetValue("Invalid package id", call.Context));
                }
            }
            else
            {
                throw new Exception(Data.Language.Hardcoded.GetValue("Missing package id", call.Context));
            }

            if (formResult.FormData.ContainsKey("category"))
            {
                update.Category = formResult.FormData["category"];
            }
            if (formResult.FormData.ContainsKey("link"))
            {
                update.Link = formResult.FormData["link"];
            }
            if (formResult.FormData.ContainsKey("description"))
            {
                update.Description = formResult.FormData["description"];
            }
            if (formResult.FormData.ContainsKey("tags"))
            {
                update.Tags = formResult.FormData["tags"];
            }
            if (formResult.FormData.ContainsKey("Images"))
            {
                update.Images = formResult.FormData["Images"];
            }

            if (formResult.FormData.ContainsKey("IsPrivate"))
            {
                string strisprivae = formResult.FormData["IsPrivate"];
                bool   isprivate   = false;
                bool.TryParse(strisprivae, out isprivate);

                if (isprivate)
                {
                    update.OrganizationId = call.Context.User.CurrentOrgId;
                }
                else
                {
                    update.OrganizationId = default(Guid);
                }
            }

            foreach (var item in formResult.Files)
            {
                string contenttype = item.ContentType;
                if (contenttype == null)
                {
                    contenttype = "image";
                }
                else
                {
                    contenttype = contenttype.ToLower();
                }

                if (contenttype.Contains("image"))
                {
                    TemplateUserImages image = new TemplateUserImages();
                    image.FileName = item.FileName;
                    image.Base64   = Convert.ToBase64String(item.Bytes);
                    update.NewImages.Add(image);
                }
                else if (contenttype.Contains("zip"))
                {
                    update.Bytes = item.Bytes;
                }
            }

            if (formResult.FormData.ContainsKey("defaultimg"))
            {
                string defaultimage = formResult.FormData["defaultimg"];
                update.NewDefault = defaultimage;
            }

            if (formResult.FormData.ContainsKey("thumbnail"))
            {
                string defaultimage = formResult.FormData["thumbnail"];
                update.NewDefault = defaultimage;
            }

            if (update.NewImages.Count() > 0)
            {
                if (formResult.FormData.ContainsKey("defaultfile"))
                {
                    string defaultimg = formResult.FormData["defaultfile"];
                    int    index      = 0;
                    if (int.TryParse(defaultimg, out index))
                    {
                        if (update.NewImages.Count() > index)
                        {
                            update.NewImages[index].IsDefault = true;
                        }
                    }
                }
            }

            IndexedDB.Serializer.Simple.SimpleConverter <TemplateUpdateModel> converter = new IndexedDB.Serializer.Simple.SimpleConverter <TemplateUpdateModel>();

            var allbytes = converter.ToBytes(update);

            string Url = Kooboo.Lib.Helper.UrlHelper.Combine(Kooboo.Data.AppSettings.ThemeUrl, "/_api/receiver/updatetemplate");

            var response = HttpHelper.PostData(Url, null, allbytes);

            if (!response)
            {
                throw new Exception(Data.Language.Hardcoded.GetValue("Update template failed", call.Context));
            }
        }