Ejemplo n.º 1
0
        public int FindOrCreate(string tableName, GenericTable tableToInsert)
        {
            using (var context = new ccnewEntities())
            {
                try {
                    var query = "SELECT Code FROM dbo." + tableName + " Where Code ={0}";

                    var result = context.ExecuteStoreQuery <string>(query, tableToInsert.Code);  //<>("");
                    if (result != null)
                    {
                        foreach (var variable in result.ToList())
                        {
                            var newquery = "SELECT Max(Iserial) FROM dbo." + tableName + " Where Code ={0}";
                            return(context.ExecuteStoreQuery <int>(newquery, tableToInsert.Code).FirstOrDefault());
                        }
                    }
                    var maxIserial = GetMaxIserial(tableName);

                    var insertQuery = "insert into dbo." + tableName +
                                      "(iserial,code,aname,ename) VALUES ({0},{1},{2},{3})";

                    context.ExecuteStoreCommand(insertQuery, maxIserial, tableToInsert.Code, tableToInsert.Aname, tableToInsert.Ename);
                    return(maxIserial);
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }
        }
Ejemplo n.º 2
0
        public GenericTable GenericUpdateOrInsert(string tablEname, GenericTable item, int index, out int outindex)
        {
            outindex = index;

            using (var context = new WorkFlowManagerDBEntities())
            {
                if (item.Iserial == 0)
                {
                    context.sp_GenericInsertIntoTable(tablEname, item.Code, item.Ename, item.Aname.Normalize());
                }
                else
                {
                    context.sp_GenericUpdateTable(tablEname, item.Iserial.ToString(), item.Code, item.Ename, item.Aname.Normalize());
                }
                context.SaveChanges();

                return(GetGeneric(tablEname, item.Code, item.Ename, item.Aname, "Iserial", "Asc").FirstOrDefault());
            }
        }