public WebFeature(Terradue.Portal.Feature entity) : base(entity)
 {
     this.Title       = entity.Title;
     this.Description = entity.Description;
     this.Image       = entity.Image;
     this.ImageStyle  = entity.ImageStyle;
     this.ButtonLink  = entity.ButtonLink;
     this.ButtonText  = entity.ButtonText;
     this.Position    = entity.Position;
     this.Dotted      = entity.Dotted;
 }
        public Terradue.Portal.Feature ToEntity(IfyContext context, Terradue.Portal.Feature input)
        {
            Terradue.Portal.Feature feat = (input == null ? new Terradue.Portal.Feature(context) : input);

            feat.Title       = this.Title;
            feat.Description = this.Description;
            feat.ButtonLink  = this.ButtonLink;
            feat.ButtonText  = this.ButtonText;
            feat.Image       = this.Image;
            feat.ImageStyle  = this.ImageStyle;
            feat.Position    = this.Position;
            feat.Dotted      = this.Dotted;

            return(feat);
        }
Beispiel #3
0
        public object Delete(DeleteFeature request)
        {
            var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly);

            try {
                context.Open();
                context.LogInfo(this, string.Format("/feature DELETE Id='{0}'", request.Id));
                Terradue.Portal.Feature feat = Terradue.Portal.Feature.FromId(context, request.Id);
                feat.Delete();

                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }
            return(new WebResponseBool(true));
        }
Beispiel #4
0
        public object Get(GetFeature request)
        {
            WebFeature result = null;

            var context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView);

            try {
                context.Open();
                context.LogInfo(this, string.Format("/feature/{{Id}} GET Id='{0}'", request.Id));
                Terradue.Portal.Feature feat = Terradue.Portal.Feature.FromId(context, request.Id);
                result = new WebFeature(feat);

                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }
            return(result);
        }
Beispiel #5
0
        public object Put(UpdateFeature request)
        {
            WebFeature result = null;

            var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly);

            try {
                context.Open();
                context.LogInfo(this, string.Format("/feature PUT Id='{0}'", request.Id));

                Terradue.Portal.Feature feat = Terradue.Portal.Feature.FromId(context, request.Id);
                feat = request.ToEntity(context, feat);
                feat.Store();
                result = new WebFeature(feat);

                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }
            return(result);
        }
Beispiel #6
0
        public object Put(SortFeature request)
        {
            var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly);

            try {
                context.Open();
                context.LogInfo(this, string.Format("/feature/sort PUT"));

                foreach (WebFeature wfeat in request)
                {
                    Terradue.Portal.Feature feat = Terradue.Portal.Feature.FromId(context, wfeat.Id);
                    feat.Position = wfeat.Position;
                    feat.Store();
                }

                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }
            return(request);
        }
Beispiel #7
0
        public object Post(UploadFeatureImage request)
        {
            var    context   = TepWebContext.GetWebContext(PagePrivileges.AdminOnly);
            string img       = "";
            string uid       = Guid.NewGuid().ToString();
            string extension = ".png";

            WebFeature result = null;

            try {
                context.Open();
                context.LogInfo(this, string.Format("/feature/{{Id}}/image POST Id='{0}'", request.Id));

                if (request.Id == 0)
                {
                    var segments = base.Request.PathInfo.Split(new[] { '/' },
                                                               StringSplitOptions.RemoveEmptyEntries);
                    request.Id = System.Int32.Parse(segments[1]);
                }

                Terradue.Portal.Feature feature = Terradue.Portal.Feature.FromId(context, request.Id);
                string oldImg = feature.Image;
                if (this.RequestContext.Files.Length > 0)
                {
                    var uploadedFile = this.RequestContext.Files[0];
                    extension = uploadedFile.FileName.Substring(uploadedFile.FileName.LastIndexOf("."));
                    img       = "/files/" + uid + extension;

                    string path = AppDomain.CurrentDomain.BaseDirectory;
                    if (!path.EndsWith("/"))
                    {
                        path += "/";
                    }

                    context.LogInfo(this, string.Format("Uploading image to {0}", path + img));
                    uploadedFile.SaveTo(path + img);
                }
                else
                {
                    using (var fileStream = File.Create("files/" + uid + extension))
                    {
                        img = "files/" + uid + extension;
                        request.RequestStream.CopyTo(fileStream);
                    }
                }
                feature.Image = img;
                feature.Store();

                result = new WebFeature(feature);

                try{
                    if (oldImg != null)
                    {
                        File.Delete("files/" + oldImg);
                    }
                }catch (Exception) {}

                context.Close();
            }catch (Exception e)
            {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }
            return(result);
        }