Ejemplo n.º 1
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));
            }
        }
Ejemplo n.º 2
0
        protected TemplateDataModel InitData(Kooboo.Lib.NETMultiplePart.FormResult formResult, ApiCall call)
        {
            TemplateDataModel data = new TemplateDataModel();

            if (formResult.FormData.ContainsKey("sitename"))
            {
                data.Name = formResult.FormData["sitename"];
            }

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

            if (formResult.FormData.ContainsKey("price"))
            {
                data.Price = decimal.Parse(formResult.FormData["price"]);
            }
            if (formResult.FormData.ContainsKey("currency"))
            {
                data.Price = decimal.Parse(formResult.FormData["currency"]);
            }

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

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

                if (isprivate)
                {
                    data.OrganizationId = call.Context.User.CurrentOrgId;
                }
            }

            foreach (var item in formResult.Files)
            {
                TemplateUserImages image = new TemplateUserImages();
                image.FileName = item.FileName;
                image.Base64   = Convert.ToBase64String(item.Bytes);
                data.Images.Add(image);
            }

            if (data.Images.Count() > 0)
            {
                if (formResult.FormData.ContainsKey("defaultimg"))
                {
                    string strindex = formResult.FormData["defaultimg"];
                    int    index    = 0;
                    int.TryParse(strindex, out index);

                    if (data.Images.Count() > index)
                    {
                        data.Images[index].IsDefault = true;
                    }
                }
            }

            return(data);
        }