public HttpResponseMessage Submit(SubmitDTO req)
 {
     try
     {
         var data = new JObject();
         data["form"] = req.form;
         string jsonSettings = ActiveModule.ModuleSettings["formsettings"] as string;
         if (!string.IsNullOrEmpty(jsonSettings))
         {
             data["formSettings"] = JObject.Parse(jsonSettings);
         }
         var module = new OpenContentModuleInfo(ActiveModule);
         Manifest.Manifest manifest = module.Settings.Manifest;
         IDataSource       ds       = DataSourceManager.GetDataSource(module.Settings.Manifest.DataSource);
         var dsContext = OpenContentUtils.CreateDataContext(module, UserInfo.UserID);
         //var source = req.form["Source"].ToString();
         var dsItem = ds.Get(dsContext, req.id);
         var res    = ds.Action(dsContext, string.IsNullOrEmpty(req.action) ? "FormSubmit" : req.action, dsItem, data);
         return(Request.CreateResponse(HttpStatusCode.OK, res));
     }
     catch (Exception exc)
     {
         Log.Logger.Error(exc);
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc));
     }
 }
        public HttpResponseMessage Submit()
        {
            SubmitDTO req      = JsonConvert.DeserializeObject <SubmitDTO>(HttpContextSource.Current.Request.Form["data"].ToString());
            var       form     = req.form;
            var       statuses = new List <FilesStatus>();

            try
            {
                //todo can we eliminate the HttpContext here
                UploadWholeFile(HttpContextSource.Current, statuses);
                var files = new JArray();
                form["Files"] = files;
                int i = 1;
                foreach (var item in statuses)
                {
                    var file = new JObject();
                    file["id"]   = item.id;
                    file["name"] = item.name;
                    file["url"]  = FormUtils.ToAbsoluteUrl(item.url);
                    files.Add(file);
                    //form["File"+i] = OpenFormUtils.ToAbsoluteUrl(item.url);
                    i++;
                }
            }
            catch (Exception exc)
            {
                Log.Logger.Error(exc);
            }
            try
            {
                var data = new JObject();
                data["form"] = req.form;
                string jsonSettings = ActiveModule.ModuleSettings["formsettings"] as string;
                if (!string.IsNullOrEmpty(jsonSettings))
                {
                    data["formSettings"] = JObject.Parse(jsonSettings);
                }
                var         module    = OpenContentModuleConfig.Create(ActiveModule, PortalSettings);
                IDataSource ds        = DataSourceManager.GetDataSource(module.Settings.Manifest.DataSource);
                var         dsContext = OpenContentUtils.CreateDataContext(module, UserInfo.UserID);
                var         dsItem    = ds.Get(dsContext, req.id);
                var         res       = ds.Action(dsContext, string.IsNullOrEmpty(req.action) ? "FormSubmit" : req.action, dsItem, data);
                return(Request.CreateResponse(HttpStatusCode.OK, res));
            }
            catch (Exception exc)
            {
                App.Services.Logger.Error(exc);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc));
            }
        }
        public HttpResponseMessage Action(SubmitDTO req)
        {
            try
            {
                var    module          = OpenContentModuleConfig.Create(ActiveModule, PortalSettings);
                string editRole        = module.Settings.Template.Manifest.GetEditRole();
                int    createdByUserid = -1;

                IDataSource ds        = DataSourceManager.GetDataSource(module.Settings.Manifest.DataSource);
                var         dsContext = OpenContentUtils.CreateDataContext(module, UserInfo.UserID);

                IDataItem dsItem = null;
                if (module.IsListMode())
                {
                    if (req.id != null)
                    {
                        var itemId = req.id;
                        dsItem = ds.Get(dsContext, itemId);
                        if (dsItem != null)
                        {
                            createdByUserid = dsItem.CreatedByUserId;
                        }
                    }
                }
                else
                {
                    dsContext.Single = true;
                    dsItem           = ds.Get(dsContext, null);
                    if (dsItem != null)
                    {
                        createdByUserid = dsItem.CreatedByUserId;
                    }
                }

                //todo: can't we do some of these checks at the beginning of this method to fail faster?
                if (!DnnPermissionsUtils.HasEditPermissions(module, editRole, createdByUserid))
                {
                    return(Request.CreateResponse(HttpStatusCode.Unauthorized));
                }
                try
                {
                    var res = ds.Action(dsContext, req.action, dsItem, req.form);
                    return(Request.CreateResponse(HttpStatusCode.OK, new
                    {
                        isValid = true,
                        result = res
                    }));
                }
                catch (DataNotValidException ex)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, new
                    {
                        isValid = false,
                        validMessage = ex.Message
                    }));
                }
            }
            catch (Exception exc)
            {
                App.Services.Logger.Error(exc);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc));
            }
        }