public static UserEdit Create(Guid id, string externalId, string userName, string fullName, string email)
        {
            var user = new UserEdit()
            {
                Id         = id,
                ExternalId = externalId,
                UserName   = userName,
                FullName   = fullName,
                Email      = email,
                Status     = EUserStatus.Active
            };

            var audit = new AuditValue();

            audit.Create(AuditHelper.UserName, AuditHelper.MachineName, AuditHelper.UtcDateTime);

            user.Audit = audit;

            MarkAsNew();

            DomainEvents.Raise(new UserCreatedEvent()
            {
                User = user
            });

            return(user);
        }
Example #2
0
        public void Test1()
        {
            using (var context = ApplicationDbContext.UseMySql())
            {
                var root = new AuditRoot {
                    LimitQuantity = 20
                };
                context.AuditRoots.Add(root);
                context.SaveChanges();

                var level1 = new AuditLevel {
                    Root = root.Id
                };
                var level2 = new AuditLevel {
                    Root = root.Id
                };
                context.AuditLevels.AddRange(level1, level2);
                context.SaveChanges();

                var value11 = new AuditValue {
                    Level = level1.Id, Quantity = 5
                };
                var value12 = new AuditValue {
                    Level = level1.Id, Quantity = 5
                };
                var value21 = new AuditValue {
                    Level = level2.Id, Quantity = 4
                };
                var value22 = new AuditValue {
                    Level = level2.Id, Quantity = 6
                };
                context.AuditValues.AddRange(value11, value12, value21, value22);
                context.SaveChanges();

                Assert.Equal(20, root.TotalQuantity);

                value11.Quantity = 8;
                context.AuditValues.Remove(value12);
                context.AuditValues.Add(new AuditValue {
                    Level = level1.Id, Quantity = 8
                });
                context.AuditLevels.Remove(level2);
                context.AuditValues.Remove(value21);
                context.SaveChanges();

                Assert.Equal(16, root.TotalQuantity);
            }

            using (var context = ApplicationDbContext.UseMySql())
            {
                var root = context.AuditRoots.First();
                context.AuditRoots.Remove(root);
                context.SaveChanges();
            }
        }
        public static OwnerEdit Create(Guid id, string name)
        {
            var owner = new OwnerEdit {
                Id = id, Name = name, Status = EOwnerStatus.Active
            };

            var audit = new AuditValue();

            audit.Create(AuditHelper.UserName, AuditHelper.MachineName, AuditHelper.UtcDateTime);

            owner.Audit = audit;

            MarkAsNew();

            DomainEvents.Raise(new OwnerCreateEvent()
            {
                Owner = owner
            });

            return(owner);
        }