예제 #1
0
        public async void ExecuteEncrpytion()
        {
            try
            {
                DateTime startDate     = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 1, 0, 1);
                DateTime endDate       = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59);
                var      lstEncrpytion = await db.TblEncryption.Where(x => x.UpdateDate > startDate && x.UpdateDate < endDate).AsNoTracking().ToListAsync();

                if (lstEncrpytion.Count > 0)
                {
                    using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                    {
                        foreach (var item in lstEncrpytion)
                        {
                            var lstCimsAttributeValue = await db.TblCimsattributeValue.Where(x => x.AttributeCode == item.AttributeCode && x.Module == item.ParentCode).ToListAsync();

                            foreach (var cimsAttributeValue in lstCimsAttributeValue)
                            {
                                if (item.EncryptionStatus != item.FinalizationStatus)
                                {
                                    if (item.EncryptionStatus == true)
                                    {
                                        cimsAttributeValue.AttributeValue  = common.EncryptStringAES(cimsAttributeValue.AttributeValue, keyString);
                                        db.Entry(cimsAttributeValue).State = EntityState.Modified;
                                        item.IsDone             = true;
                                        item.IsFirst            = false;
                                        item.FinalizationStatus = item.EncryptionStatus;
                                        db.Entry(item).State    = EntityState.Modified;
                                    }
                                    else
                                    {
                                        cimsAttributeValue.AttributeValue  = common.DecryptStringAES(cimsAttributeValue.AttributeValue, keyString);
                                        db.Entry(cimsAttributeValue).State = EntityState.Modified;
                                        item.IsDone             = true;
                                        item.IsFirst            = false;
                                        item.FinalizationStatus = item.EncryptionStatus;
                                        db.Entry(item).State    = EntityState.Modified;
                                    }
                                }
                                else
                                {
                                    item.IsDone = true;
                                }
                            }
                        }
                        await db.SaveChangesAsync();

                        scope.Complete();
                        Trace.WriteLine(EncryptionConstant.SuccessEncryption);
                    }
                }
                Trace.WriteLine(EncryptionConstant.NotExecuteEncryption);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(EncryptionConstant.FailureEncryption + ex.Message);
            }
        }
예제 #2
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
                    });
                }
            }
        }