コード例 #1
0
        private void AddSampleIfNotExists(string line)
        {
            var values = line.Split(',');

            if (values.Length < 5)
            {
                return;
            }

            var barcode   = values[1];
            var createdAt = DateTime.Parse(values[2]);
            var createdBy = int.Parse(values[3]) + 1; // Because UserId in Users.txt begin 0
            var statusId  = int.Parse(values[4]) + 1; // Because StatusId in Statuses.txt begin 0

            if (context.Samples.Any(s => s.Barcode == barcode))
            {
                return;
            }

            context.Samples.Add(new Sample
            {
                Barcode  = barcode,
                CreateAt = createdAt,
                CreateBy = createdBy,
                StatusId = statusId
            });
            context.SaveChanges();
        }
コード例 #2
0
        public async Task EnsureSeedData()
        {
            new DefaultUserCreator(context).Create();
            new DefaultStatusesCreator(context).Create();
            new DefaultSampleCreator(context).Create();

            context.SaveChanges();
        }
コード例 #3
0
        private void AddStatusIfNotExists(string line)
        {
            var values = line.Split(',');

            if (values.Length < 2)
            {
                return;
            }

            var description = values[1];

            if (context.Statuses.Any(s => s.Description == description))
            {
                return;
            }

            context.Statuses.Add(new Status {
                Description = description
            });
            context.SaveChanges();
        }
コード例 #4
0
ファイル: DefaultUserCreator.cs プロジェクト: longhuynh/ftdna
        private void AddUserIfNotExists(string line)
        {
            var values = line.Split(',');

            if (values.Length < 3)
            {
                return;
            }

            var firstName = values[1];
            var lastName  = values[2];

            if (context.Users.Any(s => s.FirstName == firstName && s.LastName == lastName))
            {
                return;
            }

            context.Users.Add(new User {
                FirstName = firstName, LastName = lastName
            });
            context.SaveChanges();
        }
コード例 #5
0
 public override TPrimaryKey InsertAndGetId(TEntity entity)
 {
     entity = Insert(entity);
     dbContext.SaveChanges();
     return(entity.Id);
 }