public static void DeleteMy(string tenant, MyWidgetInfo info)
        {
            string container = PathMapper.MapPath($"{WidgetLocation.Replace("{tenant}", tenant)}/{info.Scope}/{info.Me}");

            string filePath = Path.Combine(container, SanitizePath(info.Name) + ".json");

            if (!File.Exists(filePath))
            {
                return;
            }

            File.Delete(filePath);
        }
示例#2
0
        public async Task <ActionResult> DeleteMyAsync(MyWidgetInfo info)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.InvalidModelState(this.ModelState));
            }

            var meta = await AppUsers.GetCurrentAsync();

            info.Me = meta.UserId;

            WidigetDashboardModel.DeleteMy(this.Tenant, info);
            return(this.Ok());
        }
        public static MyWidgetInfo GetMy(string tenant, MyWidgetInfo info)
        {
            string container = PathMapper.MapPath($"{WidgetLocation.Replace("{tenant}", tenant)}/{info.Scope}/{info.Me}");
            string filePath  = Path.Combine(container, SanitizePath(info.Name) + ".json");

            if (!File.Exists(filePath))
            {
                return(info);
            }

            string contents = File.ReadAllText(filePath, new UTF8Encoding(false));

            info = JsonConvert.DeserializeObject <MyWidgetInfo>(contents);

            return(info);
        }
        public static void SaveMy(string tenant, MyWidgetInfo info)
        {
            string container = PathMapper.MapPath($"{WidgetLocation.Replace("{tenant}", tenant)}/{info.Scope}/{info.Me}");

            if (!Directory.Exists(container))
            {
                Directory.CreateDirectory(container);
            }

            string filePath = Path.Combine(container, SanitizePath(info.Name) + ".json");

            foreach (var widget in info.Widgets)
            {
                widget.Scope = info.Scope;
            }

            string contents = JsonConvert.SerializeObject(info, Formatting.Indented);

            File.WriteAllText(filePath, contents, new UTF8Encoding(false));
        }
示例#5
0
        public async Task <ActionResult> SaveMyAsync(MyWidgetInfo info)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.InvalidModelState(this.ModelState));
            }

            var meta = await AppUsers.GetCurrentAsync();

            info.Me = meta.UserId;
            try
            {
                WidigetDashboardModel.SaveMy(this.Tenant, info);
                return(this.Ok());
            }
            catch
            {
                return(this.Failed(Resources.ErrorEncounteredDuringSave, HttpStatusCode.InternalServerError));
            }
        }