Esempio n. 1
0
        protected virtual ResponseModel BatchInsert(DbConnect con, List <DynamicDictionary> items, TKey id, SaveCallBackDelegate fun = null)
        {
            ResponseModel resp = new ResponseModel(true, "OK");

            if (items?.Count > 0)
            {
                for (int i = 0, len = items.Count; i < len; i++)
                {
                    //adding parent key before saving.
                    items[i].SetValue(ParentColumnName, ParentColumnValue);
                    resp = Service.Insert(con, items[i]);
                    if (!resp.success)
                    {
                        return(resp);
                    }
                    else
                    {
                        if (fun != null)
                        {
                            DynamicDictionary dd = (DynamicDictionary)resp.data;
                            resp = fun(con, items[i], dd.GetValue <TKey>("id"));
                            if (!resp.success)
                            {
                                return(resp);
                            }
                        }
                    }
                }
            }
            return(resp);
        }
Esempio n. 2
0
        protected virtual ResponseModel BatchDelete(DbConnect con, List <DynamicDictionary> items, SaveCallBackDelegate fun = null)
        {
            ResponseModel resp = new ResponseModel(true, "OK");

            if (items?.Count > 0)
            {
                for (int i = 0, len = items.Count; i < len; i++)
                {
                    TModel mdl = new TModel();
                    mdl.LoadFromDynamicDictionary(items[i]);
                    TKey del_id = items[i].GetValue <TKey>(mdl.GetKeyPropertyName());
                    if (del_id?.ToString().Length > 0)
                    {
                        ResponseBase bs = Service.Delete(con, del_id);
                        resp.errors  = bs.errors;
                        resp.success = bs.success;
                        resp.message = bs.message;
                    }
                    if (!resp.success)
                    {
                        return(resp);
                    }
                    else
                    {
                        if (fun != null)
                        {
                            //DynamicDictionary dd = Service.GetAsDictionary(con, del_id);
                            DynamicDictionary dd = (DynamicDictionary)resp.data;
                            if (dd == null)//added for voucher detail while deleting the voucher detail grid on editing
                            {
                                resp = fun(con, items[i], del_id);
                            }
                            else
                            {
                                resp = fun(con, items[i], dd.GetValue <TKey>("id"));
                            }
                            if (!resp.success)
                            {
                                return(resp);
                            }
                        }
                    }
                }
            }
            return(resp);
        }
Esempio n. 3
0
        //Func<DbConnect, DynamicDictionary, int> fun = null)
        public virtual ResponseModel Save(DbConnect con, DynamicDictionary item, TKey id, SaveCallBackDelegate fun = null)
        {
            ResponseModel resp = new ResponseModel();

            resp.success = false;
            Errors.Clear();
            List <DynamicDictionary> items = Conversion.ToDictionaryListFromJson(item.GetValueAsString(ItemsAddedFieldName)); //get Add Data

            resp = BatchInsert(con, items, id, fun);
            if (!resp.success)
            {
                resp.message = "Error while adding records/items.";
                return(resp);
            }

            items.Clear();
            items = Conversion.ToDictionaryListFromJson(item.GetValueAsString(ItemsModifiedFieldName)); //get Add Data
            resp  = BatchUpdate(con, items, id, fun);
            if (!resp.success)
            {
                resp.message = "Error while updating records/items.";
                return(resp);
            }

            items.Clear();
            items = Conversion.ToDictionaryListFromJson(item.GetValueAsString(ItemsDeletedFieldName)); //get Add Data
            resp  = BatchDelete(con, items, fun);
            if (!resp.success)
            {
                resp.message = "Error while deleting records/items.";
                return(resp);
            }
            resp.success = true;
            resp.message = "Records saved successfully.";
            return(resp);
        }
Esempio n. 4
0
        protected virtual ResponseModel BatchUpdate(DbConnect con, List <DynamicDictionary> items, TKey id, SaveCallBackDelegate fun = null)
        {
            ResponseModel resp = new ResponseModel(true, "OK");

            if (items?.Count > 0)
            {
                for (int i = 0, len = items.Count; i < len; i++)
                {
                    TModel mdl = new TModel();
                    mdl.LoadFromDynamicDictionary(items[i]);
                    TKey item_id = items[i].GetValue <TKey>(mdl.GetKeyPropertyName());
                    resp = Service.Update(con, item_id, items[i]);
                    if (!resp.success)
                    {
                        return(resp);
                    }
                    else
                    {
                        if (fun != null)
                        {
                            DynamicDictionary dd = Service.GetAsDictionary(con, item_id);
                            //DynamicDictionary dd = (DynamicDictionary)resp.data;
                            resp = fun(con, items[i], dd.GetValue <TKey>("id"));
                            if (!resp.success)
                            {
                                return(resp);
                            }
                        }
                    }
                }
            }
            return(resp);
        }