Ejemplo n.º 1
0
        public void Article_OnBeforeSave(object sender, ArticleEventArgs e)
        {
            int count    = 0;
            var tempList = EditableContent;

            tempList.ForEach(ec =>
            {
                if (ec.Deleted)
                {
                    EditableContent.Remove(ec);
                    if (Images != null)
                    {
                        Images.ForEach(i =>
                        {
                            if (i.Position.Contains(string.Format("{0}-", (count))))
                            {
                                i.Position = "gal";
                            }
                        });
                    }
                }
                count++;
            });
            EditableContent = tempList;
        }
Ejemplo n.º 2
0
        public void SaveImages(object sender, ArticleEventArgs e)
        {
            var aRep = DependencyResolver.Current.GetService <IArticleRepository>();

            if (Images != null)
            {
                try
                {
                    string newPath = "~/Uploads/Images/" + ArticleTypeName + "/" + Uid + "/";
                    newPath = HttpContext.Current.Request.MapPath(newPath);
                    string oldPath = "~/Uploads/Images/Temp/";
                    oldPath = HttpContext.Current.Request.MapPath(oldPath);
                    if (!Directory.Exists(newPath))
                    {
                        Directory.CreateDirectory(newPath);
                    }

                    List <ArticleImage> images = new List <ArticleImage>();

                    foreach (ImageProperty imageProperty in Images)
                    {
                        if (imageProperty.Id == 0)
                        {
                            File.Move(oldPath + imageProperty.Value, newPath + imageProperty.Value);
                            File.Move(oldPath + imageProperty.Thumbnail, newPath + imageProperty.Thumbnail);
                        }

                        images.Add(this.BuildImageInterface(imageProperty.Id,
                                                            imageProperty.Value,
                                                            imageProperty.Thumbnail,
                                                            imageProperty.Position,
                                                            imageProperty.Size));
                    }

                    Images = ImageProperty.BuildXmlProperty(aRep.UpdateAllImages(images)).ToList();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }