コード例 #1
0
 public void Update(Folder entity)
 {
     using (var dbcontext = new FAXPECContext())
     {
         try
         {
             var folder = dbcontext.FOLDERS.Where(x => x.ID == (decimal)entity.Id).FirstOrDefault();
             folder = DaoSQLServerDBHelper.MapToFolderDto(entity, false);
             int resp = dbcontext.SaveChanges();
             if (resp == 0)
             {
                 throw new Exception("Nessun record aggiornato");
             }
         }
         catch (Exception ex)
         {
             if (ex.GetType() == typeof(ManagedException))
             {
                 ManagedException mEx = new ManagedException(ex.Message, "FOL_ORA002", string.Empty, string.Empty, ex);
                 ErrorLogInfo     er  = new ErrorLogInfo(mEx);
                 log.Error(er);
                 throw mEx;
             }
         }
     }
 }
コード例 #2
0
 public void Insert(Folder entity)
 {
     using (var dbcontext = new FAXPECContext())
     {
         try
         {
             if (string.IsNullOrEmpty(entity.IdNome))
             {
                 double? idnome    = dbcontext.FOLDERS.Select(x => x.IDNOME).DefaultIfEmpty(0).Max();
                 decimal newidnome = default(decimal);
                 decimal.TryParse(idnome.ToString(), out newidnome);
                 entity.IdNome = (newidnome + 1).ToString();
             }
             decimal idnew = (decimal)dbcontext.FOLDERS.Select(x => x.ID).DefaultIfEmpty(0).Max();
             entity.Id = idnew;
             FOLDERS folder = DaoSQLServerDBHelper.MapToFolderDto(entity, true);
             dbcontext.FOLDERS.Add(folder);
             entity.Id = folder.ID;
             dbcontext.SaveChanges();
         }
         catch (Exception ex)
         {
             if (ex.GetType() == typeof(ManagedException))
             {
                 ManagedException mEx = new ManagedException(ex.Message, "FOL_ORA001", string.Empty, string.Empty, ex);
                 ErrorLogInfo     er  = new ErrorLogInfo(mEx);
                 log.Error(er);
                 throw mEx;
             }
         }
     }
 }
コード例 #3
0
 public void Insert(List <Folder> entity)
 {
     using (var dbcontext = new FAXPECContext())
     {
         using (var transaction = dbcontext.Database.BeginTransaction())
         {
             try
             {
                 double? idnome    = dbcontext.FOLDERS.Select(x => x.IDNOME).DefaultIfEmpty(0).Max();
                 decimal newidnome = default(decimal);
                 decimal.TryParse(idnome.ToString(), out newidnome);
                 foreach (Folder f in entity)
                 {
                     f.IdNome = newidnome.ToString();
                     FOLDERS folder = DaoSQLServerDBHelper.MapToFolderDto(f, true);
                     dbcontext.FOLDERS.Add(folder);
                 }
             }
             catch (Exception ex)
             {
                 if (ex.GetType() == typeof(ManagedException))
                 {
                     ManagedException mEx = new ManagedException(ex.Message, "FOL_ORA001", string.Empty, string.Empty, ex);
                     ErrorLogInfo     er  = new ErrorLogInfo(mEx);
                     log.Error(er);
                     throw mEx;
                 }
             }
         }
     }
 }