Exemple #1
0
        public async Task <ResponseDTO> ExecuteEncrpytion(AttributesDTO model)
        {
            using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                try
                {
                    foreach (var item in model.tblVocattributes)
                    {
                        var label = await db.TblVocattributes.Where(x => x.AttributeCode == item.AttributeCode).AsNoTracking().FirstOrDefaultAsync();

                        var attributeEncryption = new TblEncryption();
                        attributeEncryption.AttributeCode    = item.AttributeCode;
                        attributeEncryption.AttributeLabel   = label.AttributeLabel;
                        attributeEncryption.CreatedBy        = model.UserName;
                        attributeEncryption.CreateDate       = DateTime.Now;
                        attributeEncryption.ParentCode       = item.ModuleParent;
                        attributeEncryption.EncryptionStatus = true;
                        attributeEncryption.UpdateDate       = DateTime.Now;
                        db.TblEncryption.Add(attributeEncryption);
                    }
                    await db.SaveChangesAsync();

                    scope.Complete();
                    return(new ResponseDTO()
                    {
                        StatusCode = 200, Response = CimsConstant.MS0013
                    });
                }
                catch (Exception ex)
                {
                    return(new ResponseDTO()
                    {
                        StatusCode = 400, Response = ex.Message
                    });
                }
            }
        }
Exemple #2
0
 public ResponseDTO UpdateEncrpytion(AttributeModel model, string orgCode)
 {
     using (TransactionScope scope = new TransactionScope())
     {
         try
         {
             foreach (var item in model.tblVocattributes)
             {
                 var result = db.TblEncryption.Where(x => x.AttributeCode == item.AttributeCode && x.ParentCode == item.ParentCode).FirstOrDefault();
                 if (result != null)
                 {
                     // Kiểm tra xem trường dữ liệu đã được mã hóa lần nào chưa
                     if (result.IsFirst == true)
                     {
                         db.TblEncryption.Remove(result);
                     }
                     else
                     {
                         if (result.EncryptionStatus == result.FinalizationStatus)
                         {
                             // Kiểm tra trạng thái mã hóa của trường dữ liệu
                             if (result.EncryptionStatus == true)
                             {
                                 result.EncryptionStatus = false;
                                 result.UpdatedBy        = model.UserName;
                                 //result.IsDone = true;
                                 result.IsDone          = false;
                                 db.Entry(result).State = EntityState.Modified;
                             }
                             else
                             {
                                 result.EncryptionStatus = true;
                                 result.UpdatedBy        = model.UserName;
                                 //result.IsDone = true;
                                 result.IsDone          = false;
                                 db.Entry(result).State = EntityState.Modified;
                             }
                         }
                         else
                         {
                             result.IsDone           = true;
                             result.EncryptionStatus = result.FinalizationStatus;
                         }
                     }
                 }
                 else
                 {
                     // Thêm mới trường dữ liệu cần mã hóa
                     if (item.ParentCode == EncryptionConstant.ADMIN_USER)
                     {
                         var attributeEncryption = new TblEncryption();
                         attributeEncryption.AttributeCode = item.AttributeCode;
                         if (item.AttributeLabel == EncryptionConstant.HoTen)
                         {
                             attributeEncryption.AttributeLabel = item.AttributeLabel;
                             attributeEncryption.Field          = EncryptionConstant.FullName;
                         }
                         if (item.AttributeLabel == EncryptionConstant.DiaChi)
                         {
                             attributeEncryption.AttributeLabel = item.AttributeLabel;
                             attributeEncryption.Field          = EncryptionConstant.Address;
                         }
                         attributeEncryption.CreatedBy        = model.UserName;
                         attributeEncryption.CreateDate       = DateTime.Now;
                         attributeEncryption.ParentCode       = item.ParentCode;
                         attributeEncryption.ModuleName       = item.ModuleName;
                         attributeEncryption.EncryptionStatus = true;
                         attributeEncryption.OrgCode          = orgCode;
                         attributeEncryption.IsFirst          = true;
                         attributeEncryption.IsDone           = false;
                         db.TblEncryption.Add(attributeEncryption);
                     }
                     else
                     {
                         var attributeEncryption = new TblEncryption();
                         attributeEncryption.AttributeCode    = item.AttributeCode;
                         attributeEncryption.AttributeLabel   = item.AttributeLabel;
                         attributeEncryption.CreatedBy        = model.UserName;
                         attributeEncryption.CreateDate       = DateTime.Now;
                         attributeEncryption.ParentCode       = item.ParentCode;
                         attributeEncryption.ModuleName       = item.ModuleName;
                         attributeEncryption.EncryptionStatus = true;
                         attributeEncryption.OrgCode          = orgCode;
                         attributeEncryption.IsFirst          = true;
                         attributeEncryption.IsDone           = false;
                         db.TblEncryption.Add(attributeEncryption);
                     }
                 }
             }
             db.SaveChanges();
             scope.Complete();
             return(new ResponseDTO()
             {
                 StatusCode = 200, Response = EncryptionConstant.MS0013
             });
         }
         catch (Exception ex)
         {
             return(new ResponseDTO()
             {
                 StatusCode = 500, Response = ex.Message
             });
         }
     }
 }