Example #1
0
        private void UpdateAllTests()
        {
            var allTests = _context.Tests.Include(t => t.Department);

            foreach (var test in allTests)
            {
                var tag = new Tag()
                {
                    TestId      = test.Id,
                    Value       = test.DepartmentId.ToString(),
                    Description = test.NameDescription,
                    TagTypeId   = _context.TagTypes.FirstOrDefault(tt => tt.Code == TagTypeEnums.Department.ToString()).Id,
                    Active      = true,
                    CreatedBy   = HttpContext.User.Identity.Name,
                    DateCreated = DateTime.Now
                };

                _context.Tags.Add(tag);

                try
                {
                    _context.SaveChanges();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }
            }
        }
        private void DeleteAllImagesByContainerTypeId(int containerTypeId)
        {
            var images = _context.Images.Where(img => img.CollectionContainerTypeId == containerTypeId);

            if (images.Any())
            {
                try
                {
                    _context.Images.RemoveRange(images);
                    _context.SaveChanges();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }
            }
        }