Пример #1
0
        public async Task SaveAudit(AuditChangeInputDto audit)
        {
            List <AuditEntry>          auditEntry         = new List <AuditEntry>();
            List <AuditPropertysEntry> auditpropertyentry = new List <AuditPropertysEntry>();
            AuditLog auditLog = new AuditLog();

            auditLog.BrowserInformation = audit.BrowserInformation;
            auditLog.Action             = audit.Action;
            auditLog.Ip                = audit.Ip;
            auditLog.FunctionName      = audit.FunctionName;
            auditLog.ExecutionDuration = audit.ExecutionDuration;
            //auditLog.UserId = audit.UserId;
            auditLog.ResultType = audit.ResultType;
            auditLog.Message    = audit.Message;
            foreach (var item in audit.AuditEntryInputDtos)
            {
                var model = item.MapTo <AuditEntry>();
                model.AuditLogId = auditLog.Id;
                foreach (var Property in item.PropertysEntryInputDto)
                {
                    var propertymodel = Property.MapTo <AuditPropertysEntry>();
                    propertymodel.AuditEntryId = model.Id;
                    auditpropertyentry.Add(propertymodel);
                }
                auditEntry.Add(model);
            }
            await _auditLogRepository.InsertAsync(auditLog);

            await _auditEntryRepository.InsertAsync(auditEntry.ToArray());

            await _auditPropertysEntryRepository.InsertAsync(auditpropertyentry.ToArray());
        }
Пример #2
0
        public async Task <Todos> AddTodo(Todos todo)
        {
            todo.CreatedDate = DateTime.UtcNow;
            todo.UpdatedDate = DateTime.UtcNow;
            await _todoRepository.InsertAsync(todo);

            return(todo);
        }
Пример #3
0
        /// <summary>
        /// Add User
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public async Task <Users> AddUser(Users user)
        {
            user.CreatedDate = DateTime.UtcNow;
            user.UpdatedDate = DateTime.UtcNow;
            await _userRepository.InsertAsync(user);

            return(user);
        }
Пример #4
0
        public async Task Insert_Test()
        {
            TestDB test = new TestDB();

            test.IsDeleted = false;
            test.CreatedAt = DateTime.Now;
            test.Name      = "1as32d1as3d1as32d1";
            await _mongoDBRepository.InsertAsync(test);

            var entite = await _mongoDBRepository.Entities.Where(x => x.Id == test.Id).FirstOrDefaultAsync();

            Assert.True(entite.Name == "1as32d1as3d1as32d1");
        }
Пример #5
0
        public async Task InsertEntityAsync_Test()
        {
            TestDB test = new TestDB();

            test.IsDeleted   = false;
            test.CreatedTime = DateTime.Now;
            test.Name        = "大黄瓜18CM";
            await _mongoDBRepository.InsertAsync(test);

            var entitie = await _mongoDBRepository.Entities.Where(o => o.Id == test.Id).FirstOrDefaultAsync();

            Assert.True(entitie.Name == "大黄瓜18CM");
        }
Пример #6
0
        public async Task Save(AuditLog auditLog, List <AuditEntryInputDto> auditEntry)
        {
            List <AuditEntry>          auditentrylist          = new List <AuditEntry>();
            List <AuditPropertysEntry> auditpropertysentrylist = new List <AuditPropertysEntry>();

            foreach (var item in auditEntry)
            {
                var model = item.MapTo <AuditEntry>();
                model.AuditLogId = auditLog.Id;
                foreach (var auditProperty in item.AuditPropertys)
                {
                    var auditPropertymodel = auditProperty.MapTo <AuditPropertysEntry>();
                    auditPropertymodel.AuditEntryId = model.Id;
                    auditpropertysentrylist.Add(auditPropertymodel);
                }
                auditentrylist.Add(model);
            }
            await _auditLogRepository.InsertAsync(auditLog);

            await _auditEntryRepository.InsertAsync(auditentrylist.ToArray());

            await _auditPropertysEntryRepository.InsertAsync(auditpropertysentrylist.ToArray());
        }
Пример #7
0
        public async Task <IActionResult> UpsertStudent(Student student)
        {
            var existingStudentId = Request.Form["Id"].ToString();

            if (!string.IsNullOrEmpty(existingStudentId))
            {
                student.Id = ObjectId.Parse(existingStudentId);
                await _studentRepository.UpdateAsync(student.Id, student);
            }
            else
            {
                await _studentRepository.InsertAsync(student);
            }

            return(RedirectToAction("Index"));
        }
Пример #8
0
        public async Task InsertEntityAsync_Test()
        {
            for (int i = 0; i < 100; i++)
            {
                TestDB test = new TestDB();
                test.IsDeleted   = false;
                test.CreatedTime = DateTime.Now;
                test.Name        = $"大黄瓜18CM_{i}";
                test.Id          = ObjectId.GenerateNewId();
                await _mongoDBRepository.InsertAsync(test);
            }

            var count = await _mongoDBRepository.Entities.CountAsync();

            Assert.True(count > 0);
        }
Пример #9
0
        public async Task SaveAudit(AuditLog auditLog, List <AuditEntryInputDto> audit)
        {
            List <AuditEntry>          auditEntry         = new List <AuditEntry>();
            List <AuditPropertysEntry> auditpropertyentry = new List <AuditPropertysEntry>();

            foreach (var item in audit)
            {
                var model = item.MapTo <AuditEntry>();
                model.AuditLogId = auditLog.Id;
                foreach (var Property in item.PropertysEntryInputDto)
                {
                    var propertymodel = Property.MapTo <AuditPropertysEntry>();
                    propertymodel.AuditEntryId = model.Id;
                    auditpropertyentry.Add(propertymodel);
                }
                auditEntry.Add(model);
            }
            await _auditLogRepository.InsertAsync(auditLog);

            await _auditEntryRepository.InsertAsync(auditEntry);

            await _auditPropertysEntryRepository.InsertAsync(auditpropertyentry);
        }
Пример #10
0
        public async Task SaveAsync(AuditChange auditChange)
        {
            if (auditChange != null)
            {
                var      time     = DateTime.Now;
                AuditLog auditLog = new AuditLog();
                auditLog.Action             = auditChange.Action;
                auditLog.BrowserInformation = auditChange.BrowserInformation;
                auditLog.FunctionName       = auditChange.FunctionName;
                auditLog.Ip                = auditChange.Ip;
                auditLog.OperationType     = auditChange.ResultType;
                auditLog.ExecutionDuration = auditChange.ExecutionDuration;
                auditLog.UserId            = _principal?.Identity?.GetUesrId();
                auditLog.Message           = auditChange.Message;
                auditLog.CreatedTime       = time;

                var userId = auditLog.UserId.AsTo <Guid>();
                var user   = _userManager.Users.Where(o => o.Id == userId).FirstOrDefault();
                auditLog.NickName = user?.NickName;
                auditLog.UserName = user?.UserName;

                List <AuditEntry>          auditEntryList    = new List <AuditEntry>();
                List <AuditPropertysEntry> auditPropertyList = new List <AuditPropertysEntry>();

                foreach (var item in auditChange.AuditEntitys)
                {
                    AuditEntry auditEntry = new AuditEntry();
                    auditEntry.AuditLogId        = auditLog.Id;
                    auditEntry.EntityAllName     = item.EntityName;
                    auditEntry.EntityDisplayName = item.DisplayName;
                    auditEntry.OperationType     = item.OperationType;
                    auditEntry.KeyValues         = item.KeyValues;
                    auditEntry.EntityDisplayName = item.DisplayName;
                    auditEntry.NickName          = auditLog.NickName;
                    auditEntry.UserName          = auditLog.UserName;
                    auditEntry.CreatedTime       = time;
                    foreach (var auditProperty in item.AuditPropertys)
                    {
                        AuditPropertysEntry auditPropertyModel = new AuditPropertysEntry();
                        auditPropertyModel.AuditEntryId         = auditEntry.Id;
                        auditPropertyModel.NewValues            = auditProperty.NewValues;
                        auditPropertyModel.OriginalValues       = auditProperty.OriginalValues;
                        auditPropertyModel.Properties           = auditProperty.PropertyName;
                        auditPropertyModel.PropertieDisplayName = auditProperty.PropertyDisplayName;
                        auditPropertyModel.PropertiesType       = auditProperty.PropertyType;
                        auditPropertyList.Add(auditPropertyModel);
                    }
                    auditEntryList.Add(auditEntry);
                }
                await _auditLogRepository.InsertAsync(auditLog);

                if (auditEntryList.Any())
                {
                    await _auditEntryRepository.InsertAsync(auditEntryList.ToArray());
                }

                if (auditPropertyList.Any())
                {
                    await _auditPropertysEntryRepository.InsertAsync(auditPropertyList.ToArray());
                }
            }
        }