Ejemplo n.º 1
0
        public async Task <IHttpActionResult> InsertChilds(int id, long parentId, Dictionary <string, object> Items)
        {
            var model = new CrudModel()
            {
                MetaBoID = id,
                Items    = Items
            };
            var meta = await db.META_BO.FindAsync(model.MetaBoID);

            /* ACCESS RIGHTS */
            try
            {
                UserRoleManager.Instance.VerifyWrite(meta.BO_DB_NAME);
            }
            catch (UnauthorizedAccessException ex)
            {
                return(Content(HttpStatusCode.Forbidden, ex.Message));
            }
            /* FIN ACCESS RIGHTS */

            BO bo_model = new BO()
            {
                CREATED_BY   = User.Identity.Name,
                CREATED_DATE = DateTime.Now,
                UPDATED_BY   = User.Identity.Name,
                UPDATED_DATE = DateTime.Now,
                STATUS       = "1",
                BO_TYPE      = model.MetaBoID.ToString(),
                VERSION      = meta.VERSION
            };

            db.BO.Add(bo_model);
            await db.SaveChangesAsync();

            db.BO_CHILDS.Add(new BO_CHILDS()
            {
                BO_PARENT_ID = parentId,
                BO_CHILD_ID  = bo_model.BO_ID,
                RELATION     = "1..*"
            });
            await db.SaveChangesAsync();

            int id_ = (int)bo_model.BO_ID;

            model.MetaBO = meta;
            model.Items.Add("BO_ID", id_);
            string insert = model.Insert();

            if (insert == "")
            {
                return(Ok(model));
            }
            else
            {
                return(InternalServerError(new Exception(insert)));
            }
        }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> InsertMultipleChilds(int id, List <Dictionary <string, object> > Items)
        {
            var meta = await db.META_BO.FindAsync(id);

            if (meta == null)
            {
                return(NotFound());
            }

            /* ACCESS RIGHTS */
            try
            {
                UserRoleManager.Instance.VerifyWrite(meta.BO_DB_NAME);
            }
            catch (UnauthorizedAccessException ex)
            {
                return(Content(HttpStatusCode.Forbidden, ex.Message));
            }
            /* FIN ACCESS RIGHTS */

            List <object> result  = new List <object>();
            string        insert  = "-";
            bool          deleted = false;

            foreach (var ligne in Items)
            {
                BO bo_model = new BO()
                {
                    CREATED_BY   = User.Identity.Name,
                    CREATED_DATE = DateTime.Now,
                    UPDATED_BY   = User.Identity.Name,
                    UPDATED_DATE = DateTime.Now,
                    STATUS       = "1",
                    BO_TYPE      = id.ToString(),
                    VERSION      = meta.VERSION
                };
                db.BO.Add(bo_model);
                await db.SaveChangesAsync();

                db.BO_CHILDS.Add(new BO_CHILDS()
                {
                    BO_PARENT_ID = (long)ligne["parentId"],
                    BO_CHILD_ID  = bo_model.BO_ID,
                    RELATION     = "1..*"
                });
                await db.SaveChangesAsync();

                int id_ = (int)bo_model.BO_ID;

                ligne.Remove("parentId");
                var model = new CrudModel()
                {
                    MetaBoID = id,
                    Items    = ligne,
                    MetaBO   = meta
                };
                model.Items.Add("BO_ID", id_);
                insert = model.Insert();
                result.Add(new { inserted = insert, BO_ID = id_ });

                if (insert != "")
                {
                    deleted = true;
                    db.Entry(bo_model).State = EntityState.Deleted;
                }
            }
            if (deleted)
            {
                await db.SaveChangesAsync();
            }
            return(Ok(result));
        }
Ejemplo n.º 3
0
        public async Task <IHttpActionResult> Insert(int id, Dictionary <string, object> Items)
        {
            Logger.Info("POST Crud: " + id);
            var model = new CrudModel()
            {
                MetaBoID = id,
                Items    = Items
            };
            // var meta = await db.META_BO.FindAsync(model.MetaBoID);
            var meta = db.META_BO.Find(model.MetaBoID);

            /* ACCESS RIGHTS */
            try
            {
                UserRoleManager.Instance.VerifyWrite(meta.BO_DB_NAME);
            }
            catch (UnauthorizedAccessException ex)
            {
                return(Content(HttpStatusCode.Forbidden, ex.Message));
            }
            /* FIN ACCESS RIGHTS */

            BO bo_model = new BO()
            {
                CREATED_BY   = User.Identity.Name,
                CREATED_DATE = DateTime.Now,
                UPDATED_BY   = User.Identity.Name,
                UPDATED_DATE = DateTime.Now,
                STATUS       = "1",
                BO_TYPE      = model.MetaBoID.ToString(),
                VERSION      = meta.VERSION
            };

            db.BO.Add(bo_model);
            await db.SaveChangesAsync();

            int id_ = (int)bo_model.BO_ID;

            BO_Insert_return = id_;
            model.MetaBO     = meta;
            model.BO_ID      = id_;
            model.Items.Add("BO_ID", model.BO_ID);

            //return Ok(model.FormatInsert());
            string insert = model.Insert();

            // Workflow executer begin
            var s = new SGBD();

            var db_workflow = s.Cmd(" select * from WORKFLOW CROSS APPLY OPENJSON(ITEMS) with(type varchar(50) '$.type',   " +
                                    "  precedent varchar(50) '$.precedent',     [index] int '$.index',    val nvarchar(500) '$.value.value') as jsonValues where ACTIVE = 1 and jsonValues.val = " + id +
                                    "and jsonValues.type = 'bo'");
            dynamic _JSON;

            var where = "";
            foreach (DataRow item in db_workflow.Rows)
            {
                _JSON = System.Web.Helpers.Json.Decode(item["ITEMS"].ToString());
                int level = 0;

                for (var i = (int)item["index"] + 1; i < _JSON.Length; i++)
                {
                    var elm = _JSON[i];
                    if (elm["status"] != "deleted")
                    {
                        where = "";
                        level++;
                        if (elm["type"] == "validation")
                        {
                            foreach (var rule in elm.value.rules)
                            {
                                var value = rule["value"];
                                if (!"int,float,decimal,nvarchar(MAX)".Contains(rule["field"]["DB_TYPE"]))
                                {
                                    value = "'" + value + "'";
                                }
                                where += " " + rule["logic"] + " " + rule["field"]["DB_NAME"] + " " + rule["condition"] + " " + value;
                            }

                            var check_validation = s.Cmd("select * from " + meta.BO_DB_NAME + " where BO_ID=" + model.BO_ID + "  " + where);


                            if (check_validation.Rows.Count > 0)
                            {
                                TASK valid = new TASK()
                                {
                                    BO_ID        = id_,
                                    JSON_DATA    = System.Web.Helpers.Json.Encode(elm.value.validators),
                                    CREATED_BY   = User.Identity.Name,
                                    CREATED_DATE = DateTime.Now,
                                    STATUS       = elm.value.status,
                                    ETAT         = 0,
                                    TASK_LEVEL   = level,
                                    TASK_TYPE    = "VALIDATION"
                                };

                                db.TASK.Add(valid);

                                foreach (var _validator in elm.value.validators)
                                {
                                    NOTIF notification = new NOTIF()
                                    {
                                        VALIDATOR    = _validator["email"],
                                        CREATED_DATE = DateTime.Now,
                                        ETAT         = 0
                                    };
                                    db.NOTIF.Add(notification);
                                }

                                db.SaveChanges();
                            }
                        }
                        else if (elm["type"] == "bo")
                        {
                            TASK valid = new TASK()
                            {
                                BO_ID        = id_,
                                JSON_DATA    = System.Web.Helpers.Json.Encode(elm.value),
                                CREATED_BY   = User.Identity.Name,
                                CREATED_DATE = DateTime.Now,
                                ETAT         = 0,
                                TASK_LEVEL   = level,
                                TASK_TYPE    = "BO"
                            };
                            db.TASK.Add(valid);

                            db.SaveChanges();
                            var task_id = (int)valid.TASK_ID;
                            // await Insert_Bo_Using_Mapping(id, meta.BO_DB_NAME, model.BO_ID, task_id);
                        }
                    }
                }
            }

            if (insert == "")
            {
                BO_Insert_return = id_;
                return(Ok(model));
            }
            else
            {
                return(InternalServerError(new Exception(insert)));
            }
        }