public static int delete(List<DieuKienKhuyenMaiPOS> lst)
 {
     using(var model= new SGCoopSTEntities())
     {
         foreach (var item in lst)
         {
             model.Entry(item).State = System.Data.Entity.EntityState.Deleted;
         }
         return model.SaveChanges();
     }
 }
示例#2
0
 public static void del_KMPOS(KhuyenMaiPOS obj, CTKhuyenMaiPOS objCT, List<DieuKienKhuyenMaiPOS> objDK, List<ExceptionPOS> objEX)
 {
     using(var model= new SGCoopSTEntities())
     {
         using(var trans= model.Database.BeginTransaction())
             try
             {
                 model.Entry(obj).State = System.Data.Entity.EntityState.Deleted;
                 model.Entry(objCT).State = System.Data.Entity.EntityState.Deleted;
                 model.Entry(objEX).State = System.Data.Entity.EntityState.Deleted;
                 model.Entry(objDK).State = System.Data.Entity.EntityState.Deleted;
                 model.SaveChanges();
                 trans.Commit();
             }
             catch (Exception ex)
             {
                 trans.Rollback();
                 throw new Exception(ex.Message);
             }
     }
 }
示例#3
0
 public static void update_KMPOS(KhuyenMaiPOS obj, CTKhuyenMaiPOS objCT, List<DieuKienKhuyenMaiPOS> objDK, List<ExceptionPOS> objEX)
 {
     using(var model= new SGCoopSTEntities())
     {
         using(var trans= model.Database.BeginTransaction())
             try
             {
                 model.Entry(obj).State = System.Data.Entity.EntityState.Modified;
                 model.Entry(objCT).State = System.Data.Entity.EntityState.Modified;
                 if (objEX.Count != 0)
                     model.ExceptionPOS.AddRange(objEX);
                 model.DieuKienKhuyenMaiPOS.AddRange(objDK);
                 model.SaveChanges();
                 trans.Commit();
             }
             catch (DbEntityValidationException ex)
             {
                 trans.Rollback();
                 List<string> errorMessages = new List<string>();
                 foreach (DbEntityValidationResult validationResult in ex.EntityValidationErrors)
                 {
                     string entityName = validationResult.Entry.Entity.GetType().Name;
                     foreach (DbValidationError error in validationResult.ValidationErrors)
                     {
                         errorMessages.Add(entityName + "." + error.PropertyName + ": " + error.ErrorMessage);
                     }
                 }
                 throw new Exception(errorMessages.ToString());
             }
     }
 }