Esempio n. 1
0
 public string GetWellId()
 {
     if (WellTable != null)
     {
         SqlParameter param1             = new SqlParameter("@param1", this.WellTable.TableName);
         BaseModelContext <WellModel> db = new BaseModelContext <WellModel>();
         var query = db.Database.SqlQuery <WellModel>("GetWellID @param1", param1);
         foreach (var item in query)
         {
             return(item.NewId);
         }
     }
     return(null);
 }
Esempio n. 2
0
        /// <summary>
        /// Increments Position property then calls base.SaveChanges()
        /// </summary>
        /// <returns></returns>
        public override int SaveChanges()
        {
            var entries = ChangeTracker.Entries().Where(x => x.Entity is AppFieldModel && (x.State == EntityState.Added || x.State == EntityState.Modified));

            foreach (var entry in entries)
            {
                if (((AppFieldModel)entry.Entity).Position == 0)
                {
                    BaseModelContext <AppFieldModel> db = new BaseModelContext <AppFieldModel>();
                    int nextPosition = db.Models.Where(m => m.AppId == ((AppFieldModel)entry.Entity).AppId).Count();
                    ((AppFieldModel)entry.Entity).Position = nextPosition + 1;
                }
            }
            return(base.SaveChanges());
        }