コード例 #1
0
        public virtual IHttpActionResult Get(string id)
        {
            try
            {
                Durados.Web.Mvc.View view = (Durados.Web.Mvc.View)Maps.Instance.DuradosMap.Database.Views[viewName];
                if (view == null)
                {
                    return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NotFound, string.Format(Messages.ViewNameNotFound, viewName))));
                }

                if (string.IsNullOrEmpty(id))
                {
                    return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NotFound, Messages.IdIsMissing)));
                }

                if (!view.IsAllow())
                {
                    return(ResponseMessage(Request.CreateResponse(HttpStatusCode.Forbidden, Messages.ViewIsUnauthorized)));
                }

                var item = RestHelper.Get(view, id, false, view_BeforeSelect, view_AfterSelect, false, false, true);

                if (item == null)
                {
                    return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NotFound, string.Format(Messages.ItemWithIdNotFound, id, viewName))));
                }

                return(Ok(item));
            }
            catch (Exception exception)
            {
                throw new BackAndApiUnexpectedResponseException(exception, this);
            }
        }
コード例 #2
0
        public IHttpActionResult Get(string guid, int limit = 1000)
        {
            JavaScriptSerializer jss    = new JavaScriptSerializer();
            List <IActionEvent>  events = new List <IActionEvent>();

            try
            {
                Durados.Web.Mvc.View view = GetView("durados_Log");

                int rowCount = -1;

                Dictionary <string, object>[] filterArray = new Dictionary <string, object>[2] {
                    new Dictionary <string, object>()
                    {
                        { "fieldName", "Guid" }, { "operator", FilterOperandType.equals.ToString() }, { "value", guid }
                    }, new Dictionary <string, object>()
                    {
                        { "fieldName", "LogType" }, { "operator", FilterOperandType.greaterThan.ToString() }, { "value", 501 }
                    }
                };
                Dictionary <string, object>[] sortArray = new Dictionary <string, object>[1] {
                    new Dictionary <string, object>()
                    {
                        { "fieldName", "Time" }, { "order", "asc" }
                    }
                };

                var items = (Dictionary <string, object>)RestHelper.Get(view, false, false, 1, limit * 2 + 1, filterArray, null, sortArray, out rowCount, false, view_BeforeSelect, view_AfterSelect, false, false, false, false, null, true, false);

                if (rowCount > limit)
                {
                    return(ResponseMessage(Request.CreateResponse(HttpStatusCode.PreconditionFailed, "Number of actions is more than " + limit)));
                }

                var data = (Dictionary <string, object>[])items["data"];


                foreach (Dictionary <string, object> item in data)
                {
                    var          actionEventData = jss.Deserialize <Dictionary <string, object> >(item["FreeText"].ToString());
                    IActionEvent actionEvent     = new ActionEvent((int)actionEventData["time"], (Event)Enum.Parse(typeof(Event), actionEventData["event"].ToString(), true), actionEventData["objectName"].ToString(), actionEventData["actionName"].ToString(), actionEventData["id"].ToString(), actionEventData["data"]);
                    events.Add(actionEvent);
                }

                CallStackConverter callStackConverter = new CallStackConverter();

                var result = callStackConverter.ChronologicalListToTree(events.OrderBy(e => e.Time).ToList());
                if (result == null)
                {
                    return(Ok(new { }));
                }
                return(Json(result, ViewHelpers.CamelCase));
            }
            catch (Exception exception)
            {
                string eventsJson = jss.Serialize(events);
                Maps.Instance.DuradosMap.Logger.Log("", "", "", exception, 1, eventsJson);
                throw new BackAndApiUnexpectedResponseException(exception, this);
            }
        }
コード例 #3
0
        public virtual IHttpActionResult Delete(string id, string parameters = null)
        {
            try
            {
                if (string.IsNullOrEmpty(id))
                {
                    return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NotFound, Messages.IdIsMissing)));
                }

                Durados.Web.Mvc.View view = (Durados.Web.Mvc.View)Maps.Instance.DuradosMap.Database.Views[viewName];
                if (view == null)
                {
                    return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NotFound, string.Format(Messages.ViewNameNotFound, viewName))));
                }

                if (!view.IsDeletable())
                {
                    return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NotFound, Messages.ViewIsUnauthorized)));
                }

                Dictionary <string, object> values = null;

                if (!string.IsNullOrEmpty(parameters))
                {
                    values = new Dictionary <string, object>();
                    Dictionary <string, object> rulesParameters = view.Deserialize(System.Web.HttpContext.Current.Server.UrlDecode(parameters));
                    foreach (string key in rulesParameters.Keys)
                    {
                        if (!values.ContainsKey(key))
                        {
                            values.Add(key.AsToken(), rulesParameters[key]);
                        }
                    }
                }

                view.Delete(id, false, view_BeforeDelete, view_AfterDeleteBeforeCommit, view_AfterDeleteAfterCommit, values, true);


                return(Ok(new { __metadata = new { id = id } }));
            }
            catch (RowNotFoundException exception)
            {
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NotFound, exception.Message)));
            }
            catch (System.Data.Common.DbException exception)
            {
                string message = exception.Message;
                if (message.StartsWith("The DELETE statement conflicted with the REFERENCE constraint"))
                {
                    message = Messages.ForeignKeyDeleteViolation;
                }
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.ExpectationFailed, message)));
            }

            catch (Exception exception)
            {
                throw new BackAndApiUnexpectedResponseException(exception, this);
            }
        }
コード例 #4
0
        public virtual IHttpActionResult Post(bool?returnObject = null, string parameters = null)
        {
            try
            {
                Durados.Web.Mvc.View view = (Durados.Web.Mvc.View)Maps.Instance.DuradosMap.Database.Views[viewName];
                if (view == null)
                {
                    return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NotFound, string.Format(Messages.ViewNameNotFound, viewName))));
                }
                if (!view.IsCreatable() && !view.IsDuplicatable())
                {
                    return(ResponseMessage(Request.CreateResponse(HttpStatusCode.Forbidden, Messages.ActionIsUnauthorized)));
                }

                string json = System.Web.HttpContext.Current.Server.UrlDecode(Request.Content.ReadAsStringAsync().Result.Replace("%22", "%2522").Replace("%2B", "%252B").Replace("+", "%2B"));

                Dictionary <string, object>[] values = GetParameters(parameters, view, json);

                string pk = view.Create(values, false, view_BeforeCreate, view_BeforeCreateInDatabase, view_AfterCreateBeforeCommit, view_AfterCreateAfterCommit, true);

                string[] pkArray       = pk.Split(';');
                int      pkArrayLength = pkArray.Length;

                if (returnObject.HasValue && returnObject.Value && pkArrayLength == 1)
                {
                    var item = RestHelper.Get(view, pk, false, view_BeforeSelect, view_AfterSelect);
                    return(Ok(item));
                }
                else if (returnObject.HasValue && returnObject.Value && pkArrayLength > 1 && pkArrayLength <= 100)
                {
                    List <Dictionary <string, object> > data = new List <Dictionary <string, object> >();
                    foreach (string key in pkArray)
                    {
                        var item = RestHelper.Get(view, key, false, view_BeforeSelect, view_AfterSelect);
                        data.Add(item);
                    }

                    Dictionary <string, object> items = new Dictionary <string, object>();
                    items.Add("totalRows", pkArrayLength);
                    items.Add("data", data.ToArray());

                    return(Ok(items));
                }

                object id = pk;
                if (pkArrayLength > 1)
                {
                    id = pkArray;
                }
                return(Ok(new { __metadata = new { id = id } }));
            }
            catch (Exception exception)
            {
                throw new BackAndApiUnexpectedResponseException(exception, this);
            }
        }
コード例 #5
0
ファイル: cronController.cs プロジェクト: yarivat/Admin
        private bool IsOverTheLimit(Durados.Web.Mvc.View view)
        {
            int count;

            view.FillPage(1, 100000, null, null, null, out count, null, null);

            int limit = Map.GetLimit(Limits.Cron);

            return(count >= limit);
        }
コード例 #6
0
ファイル: CmsHelper.cs プロジェクト: yarivat/Admin
        public static string GetHtml(string key)
        {
            Durados.Web.Mvc.View htmlView = GetHtmlView();
            DataRow htmlRow = htmlView.GetDataRow(key);

            if (htmlRow == null)
            {
                return(string.Empty);
            }

            return(HttpContext.Current.Server.HtmlDecode(htmlView.GetDisplayValue(GetHtmlFieldName(), htmlRow)));
        }
コード例 #7
0
        public IHttpActionResult Last()
        {
            SqlAccess sa = new SqlAccess();

            Durados.Web.Mvc.View logView = (Durados.Web.Mvc.View)map.Database.Views["Durados_Log"];

            Dictionary <string, object> values = new Dictionary <string, object>();

            values.Add(logView.GetFieldByColumnNames("LogType").Name, "-611");
            int      rowCount = 0;
            DataView dataView = logView.FillPage(1, 1, values, false, new Dictionary <string, SortDirection>()
            {
                { "ID", SortDirection.Desc }
            }, out rowCount, null, null);

            if (dataView.Count == 0)
            {
                return(NotFound());
            }

            string   guid      = (string)dataView[0]["Action"];
            DateTime timestamp = (DateTime)dataView[0]["Time"];

            values = new Dictionary <string, object>();
            values.Add(logView.GetFieldByColumnNames("LogType").Name, "-611");
            values.Add(logView.GetFieldByColumnNames("Action").Name, guid);
            rowCount = 0;
            dataView = logView.FillPage(1, 1, values, false, new Dictionary <string, SortDirection>()
            {
                { "MethodName", SortDirection.Asc }
            }, out rowCount, null, null);

            string model = string.Empty;
            string sql   = string.Empty;

            foreach (System.Data.DataRowView row in dataView)
            {
                if (!row.Row.IsNull("Trace"))
                {
                    model += row["Trace"].ToString();
                }

                if (!row.Row.IsNull("FreeText"))
                {
                    sql += row["FreeText"].ToString();
                }
            }

            return(Ok(new { model = model, sql = sql, timestamp = timestamp }));
        }
コード例 #8
0
        protected override Dictionary <string, object> GetAdjustedValues(Durados.Web.Mvc.View view, Dictionary <string, object> values)
        {
            const string viewTable = "viewTable";

            if (values.ContainsKey(viewTable))
            {
                string viewName = values[viewTable].ToString();
                if (Map.Database.Views.ContainsKey(viewName))
                {
                    values[viewTable] = Map.Database.Views[viewName].ID;
                }
            }

            return(base.GetAdjustedValues(view, values));
        }
コード例 #9
0
        public virtual IHttpActionResult Put(string id, bool?returnObject = null, string parameters = null)
        {
            try
            {
                if (string.IsNullOrEmpty(id) || id.Equals("undefined"))
                {
                    return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NotFound, Messages.IdIsMissing)));
                }

                Durados.Web.Mvc.View view = (Durados.Web.Mvc.View)Maps.Instance.DuradosMap.Database.Views[viewName];
                if (view == null)
                {
                    return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NotFound, string.Format(Messages.ViewNameNotFound, viewName))));
                }

                if (!view.IsEditable())
                {
                    return(ResponseMessage(Request.CreateResponse(HttpStatusCode.Forbidden, Messages.ActionIsUnauthorized)));
                }

                string json = System.Web.HttpContext.Current.Server.UrlDecode(Request.Content.ReadAsStringAsync().Result.Replace("%22", "%2522").Replace("%2B", "%252B").Replace("+", "%2B"));

                if (string.IsNullOrEmpty(json))
                {
                    return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NotFound, Messages.MissingObjectToUpdate)));
                }

                Dictionary <string, object> values2 = view.Deserialize(json);

                Dictionary <string, object> values = GetParameters(parameters, view, values2);

                view.Update(values, id, false, view_BeforeEdit, view_BeforeEditInDatabase, view_AfterEditBeforeCommit, view_AfterEditAfterCommit, view_BeforeCreate, view_BeforeCreateInDatabase, view_AfterCreateBeforeCommit, view_AfterCreateAfterCommit, false, view_BeforeDelete, view_AfterDeleteBeforeCommit, view_AfterDeleteAfterCommit, true);

                if (returnObject.HasValue && returnObject.Value)
                {
                    var item = RestHelper.Get(view, id, false, view_BeforeSelect, view_AfterSelect);
                    return(Ok(item));
                }

                return(Ok());
            }
            catch (Exception exception)
            {
                throw new BackAndApiUnexpectedResponseException(exception, this);
            }
        }
コード例 #10
0
ファイル: CmsHelper.cs プロジェクト: yarivat/Admin
        public static string GetContent(string key)
        {
            string content = GetHtml(key);

            if (string.IsNullOrEmpty(content))
            {
                Durados.Web.Mvc.View htmlView = GetMainHtmlView();
                DataRow htmlRow = htmlView.GetDataRow(key);

                if (htmlRow == null)
                {
                    return(string.Empty);
                }

                content = HttpContext.Current.Server.HtmlDecode(htmlView.GetDisplayValue(GetHtmlFieldName(), htmlRow));
            }

            return(content);
        }
コード例 #11
0
ファイル: cronController.cs プロジェクト: yarivat/Admin
        protected override IHttpActionResult ValidateInputForUpdate(string id, Durados.Web.Mvc.View view, Dictionary <string, object> values)
        {
            if (values.ContainsKey(NAME))
            {
                string name = values[NAME].ToString();
                if (Map.Database.Crons.Values.Where(c => c.Name == name && c.ID.ToString() != id).FirstOrDefault() != null)
                {
                    return(ResponseMessage(Request.CreateResponse(HttpStatusCode.Conflict, string.Format(Messages.CronWithNameAlreadyExists, name))));
                }
            }

            if (values.ContainsKey(DATABASE))
            {
                values[DATABASE] = 0;
            }
            else
            {
                values.Add(DATABASE, 0);
            }

            return(null);
        }
コード例 #12
0
        private static Dictionary <string, object> GetParameters(string parameters, Durados.Web.Mvc.View view, Dictionary <string, object> values)
        {
            Dictionary <string, object> values2 = new Dictionary <string, object>();

            if (!string.IsNullOrEmpty(parameters))
            {
                Dictionary <string, object> rulesParameters = view.Deserialize(System.Web.HttpContext.Current.Server.UrlDecode(parameters));
                foreach (string key in rulesParameters.Keys)
                {
                    //if (values.ContainsKey(key))
                    //{
                    //    throw new Durados.DuradosException("The name of a parameter cannot be the same as a field.");
                    //}
                    values2.Add(key.AsToken(), rulesParameters[key]);
                }
            }
            foreach (string key in values.Keys)
            {
                values2.Add(key, values[key]);
            }
            return(values2);
        }
コード例 #13
0
ファイル: CmsHelper.cs プロジェクト: yarivat/Admin
        public static void SetHtml(string key, string value)
        {
            Durados.Web.Mvc.View htmlView = GetHtmlView();
            DataRow htmlRow = htmlView.GetDataRow(key);

            if (htmlRow == null)
            {
                if (htmlView.AllowCreate)
                {
                    Dictionary <string, object> values = new Dictionary <string, object>();
                    values.Add("Name", key);
                    values.Add("Text", value);
                    htmlView.Create(values);
                }
                else
                {
                    htmlView.AllowCreate = true;
                    try
                    {
                        Dictionary <string, object> values = new Dictionary <string, object>();
                        values.Add("Name", key);
                        values.Add("Text", value);
                        htmlView.Create(values);
                    }
                    catch { };
                    htmlView.AllowCreate = false;
                }
            }
            else
            {
                Dictionary <string, object> values = new Dictionary <string, object>();
                values.Add("Text", value);

                htmlView.Edit(values, key, null, null, null, null);
            }
        }
コード例 #14
0
        public IHttpActionResult Put(string appName)
        {
            try
            {
                if (!Maps.IsDevUser())
                {
                    return(ResponseMessage(Request.CreateResponse(HttpStatusCode.Unauthorized, Messages.ActionIsUnauthorized)));
                }

                string json = Request.Content.ReadAsStringAsync().Result;

                if (string.IsNullOrEmpty(json))
                {
                    return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NotFound, Messages.MissingObjectToUpdate)));
                }

                json = System.Web.HttpContext.Current.Server.UrlDecode(json.Replace("%22", "%2522").Replace("%2B", "%252B").Replace("+", "%2B"));

                Dictionary <string, object> values = Durados.Web.Mvc.UI.Json.JsonSerializer.Deserialize(json);

                int?id = Maps.Instance.AppExists(appName);

                if (!id.HasValue)
                {
                    return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NotFound, string.Format(Messages.AppNotFound, appName))));
                }

                string pk = id.Value.ToString();

                Durados.Web.Mvc.View appsView = (Durados.Web.Mvc.View)Maps.Instance.DuradosMap.Database.Views["durados_App"];
                int PaymentStatus             = System.Convert.ToInt32(values["PaymentStatus"]);

                appsView.Edit(new Dictionary <string, object>()
                {
                    { "PaymentStatus", PaymentStatus }
                }, pk, view_BeforeEdit, view_BeforeEditInDatabase, view_AfterEditBeforeCommit, view_AfterEditAfterCommit);

                //string sql = string.Empty;
                //if (values.ContainsKey("PaymentStatus"))
                //{
                //    string PaymentStatus = values["PaymentStatus"].ToString();
                //    sql = "update [durados_App] set [PaymentStatus] = " + PaymentStatus + " where [durados_App].[Id] = " + pk + ";";

                //}
                //if (values.ContainsKey("PaymentLocked"))
                //{
                //    string PaymentLocked = values["PaymentLocked"].ToString();
                //    sql += "update [durados_App] set [PaymentLocked] = " + PaymentLocked + " where [durados_App].[Id] = " + pk + ";";

                //}

                //SqlAccess sa = new SqlAccess();

                //sa.ExecuteNonQuery(Maps.Instance.DuradosMap.Database.ConnectionString, sql);

                Reload(appName);

                return(Ok());
            }
            catch (Exception exception)
            {
                throw new BackAndApiUnexpectedResponseException(exception, this);
            }
        }
コード例 #15
0
 protected virtual bool IsAllow(Durados.Web.Mvc.View view)
 {
     return(view.IsAllow());
 }
コード例 #16
0
ファイル: fileController.cs プロジェクト: yarivat/Admin
        [HttpPost] // This is from System.Web.Http, and not from System.Web.Mvc
        public HttpResponseMessage Upload(string viewName, string fieldName)
        {
            if (string.IsNullOrEmpty(viewName))
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, Messages.ViewNameIsMissing));
            }

            Durados.Web.Mvc.View view = GetView(viewName);
            if (view == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, string.Format(Messages.ViewNameNotFound, viewName)));
            }

            if (string.IsNullOrEmpty(fieldName))
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, Messages.FieldNameIsMissing));
            }

            Durados.Field[] fields = view.GetFieldsByJsonName(fieldName);
            if (fields.Length == 0)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, string.Format(Messages.FieldNameNotFound, fieldName)));
            }

            Durados.Field field = fields[0];

            if (!(field.FieldType == Durados.FieldType.Column && ((ColumnField)field).FtpUpload != null))
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, string.Format(Messages.UploadNotFound, fieldName)));
            }

            Durados.Web.Mvc.ColumnField columnField = (Durados.Web.Mvc.ColumnField)field;

            //if (!Request.Content.IsMimeMultipartContent())
            //{
            //    this.Request.CreateResponse(HttpStatusCode.UnsupportedMediaType);
            //}

            //var provider = GetMultipartProvider();
            //var result = Request.Content.ReadAsMultipartAsync(provider);
            //var result = await Request.Content.ReadAsMultipartAsync();

            // On upload, files are given a generic name like "BodyPart_26d6abe1-3ae1-416a-9429-b35f15e6e5d5"
            // so this is how you can get the original file name
            //var originalFileName = GetDeserializedFileName(result.FileData.First());

            //string strFileName = originalFileName;

            // uploadedFileInfo object will give you some additional stuff like file length,
            // creation time, directory name, a few filesystem methods etc..
            //var uploadedFileInfo = new FileInfo(result.FileData.First().LocalFileName);

            //string strExtension = Path.GetExtension(originalFileName).ToLower().TrimStart('.');

            List <object> files = new List <object>();

            foreach (string key in System.Web.HttpContext.Current.Request.Files.AllKeys)
            {
                var file = System.Web.HttpContext.Current.Request.Files[key];

                string strFileName = Path.GetFileName(file.FileName);

                try
                {
                    string strExtension = Path.GetExtension(strFileName).ToLower().TrimStart('.');

                    if (!FtpUploadValidExtension(strExtension))
                    {
                        //return Request.CreateResponse(HttpStatusCode.UnsupportedMediaType, Messages.InvalidFileType);
                        files.Add(new { fileName = strFileName, success = false, error = "Invalid file type" });
                        continue;
                    }

                    if (!string.IsNullOrEmpty(columnField.FtpUpload.FileAllowedTypes))
                    {
                        string[] exts = columnField.FtpUpload.FileAllowedTypes.Split(',');

                        bool valid = false;

                        foreach (string ext in exts)
                        {
                            if (ext.Trim().Equals(strExtension))
                            {
                                valid = true;
                                break;
                            }
                        }
                        if (!valid)
                        {
                            files.Add(new { fileName = strFileName, success = false, error = "Invalid file type" });
                            continue;
                            //return Request.CreateResponse(HttpStatusCode.UnsupportedMediaType, string.Format(Messages.InvalidFileType2, columnField.DisplayName, columnField.FtpUpload.FileAllowedTypes));
                        }
                    }

                    //float fileSize = (uploadedFileInfo.Length / 1024) / 1000;
                    float fileSize = (file.ContentLength / 1024) / 1000;

                    if (!FtpUploadValidSize(columnField, fileSize))
                    {
                        files.Add(new { fileName = strFileName, success = false, error = "The file is too big" });
                        continue;

                        //throw new Exception("The file has exceeded the size limit.");
                    }

                    if (!FtpUploadValidFolderSize(columnField, fileSize))
                    {
                        files.Add(new { fileName = strFileName, success = false, error = "Total files exceeded quota" });
                        continue;

                        //throw new Exception("The folder has exceeded the size limit.");
                    }

                    if (columnField.FtpUpload.FileMaxSize > 0)
                    {
                        if (fileSize > columnField.FtpUpload.FileMaxSize)
                        {
                            //throw new Exception("File too big in field [" + field.DisplayName + "].<br><br>Max Allowed size: " + columnField.FtpUpload.FileMaxSize + " MB");
                            files.Add(new { fileName = strFileName, success = false, error = "The file is too big" });
                            continue;
                        }
                    }

                    string strSaveLocation = string.Empty;

                    string src = string.Empty;

                    if (columnField.FtpUpload.StorageType == StorageType.Azure)
                    {
                        src = SaveUploadedFileToAzure(columnField, strFileName, file.ContentType, file.InputStream);
                    }
                    else if (columnField.FtpUpload.StorageType == StorageType.Aws)
                    {
                        src = SaveUploadedFileToAws(columnField, strFileName, file.ContentType, file.InputStream);
                    }
                    else
                    {
                        SaveUploadedFileToFtp(columnField, strFileName, file.ContentType, file.InputStream);

                        if (columnField.FtpUpload.StorageType != StorageType.Azure)
                        {
                            src = columnField.FtpUpload.DirectoryVirtualPath.TrimEnd('/') + "/" + ((string.IsNullOrEmpty(columnField.FtpUpload.DirectoryBasePath)) ? string.Empty : (columnField.FtpUpload.DirectoryBasePath.TrimStart('/').TrimEnd('/') + "/")) + strFileName;
                        }
                        else
                        {
                            src = System.Web.HttpContext.Current.Server.UrlEncode((new Durados.Web.Mvc.UI.ColumnFieldViewer()).GetDownloadUrl(columnField, string.Empty));
                        }
                    }

                    files.Add(new { fileName = strFileName, url = src, success = true });
                }
                catch (Exception exception)
                {
                    files.Add(new { fileName = strFileName, success = false, error = exception.Message });
                    continue;
                }
            }

            // Through the request response you can return an object to the Angular controller
            // You will be able to access this in the .success callback through its data attribute
            // If you want to send something to the .error callback, use the HttpStatusCode.BadRequest instead
            return(this.Request.CreateResponse(HttpStatusCode.OK, new { files = files }));
        }
コード例 #17
0
        public virtual IHttpActionResult Get(int?pageNumber = null, int?pageSize = null, string filter = null, string sort = null, string search = null, bool?deep = null, bool descriptive = true)
        {
            try
            {
                Durados.Web.Mvc.View view = (Durados.Web.Mvc.View)Maps.Instance.DuradosMap.Database.Views[viewName];
                if (view == null)
                {
                    return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NotFound, string.Format(Messages.ViewNameNotFound, viewName))));
                }
                if (!IsAllow(view))
                {
                    return(ResponseMessage(Request.CreateResponse(HttpStatusCode.Forbidden, Messages.ViewIsUnauthorized)));
                }

                int rowCount = 0;

                Dictionary <string, object>[] filterArray = null;

                if (!string.IsNullOrEmpty(filter) && filter != "filter" && filter != "false" && filter != "null" && filter != "undefined" && filter != "[{}]")
                {
                    if (filter == "(Collection)")
                    {
                        filter = "[" + System.Web.HttpContext.Current.Request.Params["filter"] + "]";
                    }
                    if (filter.StartsWith("{"))
                    {
                        filter = "[" + filter + "]";
                    }
                    try
                    {
                        filterArray = JsonConverter.DeserializeArray(filter);
                    }
                    catch (Exception exception)
                    {
                        Map.Logger.Log(GetControllerNameForLog(this.ControllerContext), "get", exception.Source, exception, 1, "Deserialize filter " + filter + ", original: " + System.Web.HttpContext.Current.Request.Params["filter"]);
                        return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NotAcceptable, Messages.StringifyFilter)));
                    }
                }

                Dictionary <string, object>[] sortArray = null;

                if (!string.IsNullOrEmpty(sort) && sort != "sort" && sort != "false" && sort != "null" && sort != "undefined" && sort != "[{}]")
                {
                    if (sort == "(Collection)")
                    {
                        sort = "[" + System.Web.HttpContext.Current.Request.Params["sort"] + "]";
                    }
                    if (sort.StartsWith("{"))
                    {
                        sort = "[" + sort + "]";
                    }
                    try
                    {
                        sortArray = JsonConverter.DeserializeArray(sort);
                    }
                    catch (Exception exception)
                    {
                        Map.Logger.Log(GetControllerNameForLog(this.ControllerContext), "get", exception.Source, exception, 1, "Deserialize sort " + sort + ", original: " + System.Web.HttpContext.Current.Request.Params["sort"]);
                        return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NotAcceptable, Messages.StringifySort)));
                    }
                }

                if (search == "null" || search == "undefined")
                {
                    search = null;
                }

                var items = RestHelper.Get(view, false, false, pageNumber ?? 1, pageSize ?? 200, filterArray, search, sortArray, out rowCount, deep ?? false, view_BeforeSelect, view_AfterSelect, false, descriptive, true);

                return(Ok(items));
            }
            catch (FilterException exception)
            {
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NotAcceptable, exception.Message)));
            }
            catch (SortException exception)
            {
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NotAcceptable, exception.Message)));
            }
            catch (Exception exception)
            {
                throw new BackAndApiUnexpectedResponseException(exception, this);
            }
        }
コード例 #18
0
        private static Dictionary <string, object>[] GetParameters(string parameters, Durados.Web.Mvc.View view, string json)
        {
            if (string.IsNullOrEmpty(json))
            {
                return(new Dictionary <string, object>[1] {
                    new Dictionary <string, object>()
                });
            }
            if (json.StartsWith("["))
            {
                Dictionary <string, object>[] valuesArray = JsonConverter.DeserializeArray(json);

                List <Dictionary <string, object> > list = new List <Dictionary <string, object> >();

                foreach (var values in valuesArray)
                {
                    Dictionary <string, object> valuesWithParameters = GetParameters(parameters, view, values);
                    list.Add(valuesWithParameters);
                }

                return(list.ToArray());
            }
            else
            {
                Dictionary <string, object> values = view.Deserialize(json);

                return(new Dictionary <string, object>[1] {
                    GetParameters(parameters, view, values)
                });
            }
        }
コード例 #19
0
ファイル: cronController.cs プロジェクト: yarivat/Admin
        protected override IHttpActionResult ValidateInputForPost(Durados.Web.Mvc.View view, Dictionary <string, object> values)
        {
            if (IsOverTheLimit(view))
            {
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.PreconditionFailed, "You have exceeded the limit of maximum crons allowed")));
            }


            if (values.ContainsKey(NAME))
            {
                string name = values[NAME].ToString();
                if (Map.Database.Crons.Values.Where(c => c.Name == name).FirstOrDefault() != null)
                {
                    return(ResponseMessage(Request.CreateResponse(HttpStatusCode.Conflict, string.Format(Messages.CronWithNameAlreadyExists, name))));
                }
            }

            if (!values.ContainsKey(CRON_TYPE))
            {
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.PreconditionFailed, "Missing CronType")));
            }

            string cronType = values[CRON_TYPE].ToString();

            if (cronType != CronType.External.ToString() && !values.ContainsKey(EntityId))
            {
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.PreconditionFailed, "Missing EntityId")));
            }

            int entityId = -1;

            if (!int.TryParse(values[EntityId].ToString(), out entityId))
            {
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.PreconditionFailed, "EntityId must be a number")));
            }

            if (cronType == CronType.Query.ToString())
            {
                if (Map.Database.Queries.Values.Where(q => q.ID == entityId).FirstOrDefault() == null)
                {
                    return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NotFound, "Query not found for id " + entityId)));
                }
            }

            if (cronType == CronType.Action.ToString())
            {
                ConfigAccess configAccess = new ConfigAccess();
                DataRow      row          = configAccess.GetRow("Rule", "ID", entityId.ToString(), map.GetConfigDatabase().ConnectionString);

                if (row == null)
                {
                    return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NotFound, "Action not found for id " + entityId)));
                }
            }


            if (values.ContainsKey(DATABASE))
            {
                values[DATABASE] = 0;
            }
            else
            {
                values.Add(DATABASE, 0);
            }

            return(null);
        }