예제 #1
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);
            }
        }
예제 #2
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);
            }
        }