public static void TestInit(TestContext context)
        {
            //TextWriterTraceListener myCreator = new TextWriterTraceListener(System.Console.Out);
            //Trace.Listeners.Add(myCreator);
            string logFolder = ConfigurationManager.AppSettings["LogPath"];
            var logPath = Path.Combine(logFolder, string.Format("{0}Trace.txt", DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss")));
            Trace.Listeners.Add(new TextWriterTraceListener(logPath));

            IServiceContext serviceContext = ServiceContext.NewServiceContext("*****@*****.**", "", "", "Arcserve", DataProtectInterface.TaskType.Catalog);
            serviceContext.CurrentMailbox = "*****@*****.**";
            var dataAccess = CatalogFactory.Instance.NewCatalogDataAccessInternal(serviceContext.Argument, serviceContext.AdminInfo.OrganizationName);
            dataAccess.ResetAllStorage(serviceContext.CurrentMailbox);

            if (!FactoryBase.IsRunningOnAzureOrStorageInAzure())
            {

                using (CatalogDbContext dbContext = new CatalogDbContext(new SqlDbImpl.Model.OrganizationModel() { Name = "Arcserve" }))
                {
                    dbContext.Folders.RemoveRange(dbContext.Folders);
                    dbContext.ItemLocations.RemoveRange(dbContext.ItemLocations);
                    dbContext.Items.RemoveRange(dbContext.Items);
                    dbContext.Catalogs.RemoveRange(dbContext.Catalogs);
                    dbContext.Mailboxes.RemoveRange(dbContext.Mailboxes);

                    dbContext.SaveChanges();
                }
            }
        }
        public void SaveProductItem(ProductItem entity)
        {
            if (entity.Id == default)
            {
                context.Entry(entity).State = EntityState.Added;
                context.SaveChanges();
                foreach (Image img in entity.Images)
                {
                    context.Entry(img).State = EntityState.Added;
                }
                foreach (Size size in entity.Sizes)
                {
                    context.Entry(size).State = EntityState.Added;
                }
            }
            else
            {
                foreach (Image img in entity.Images)
                {
                    context.Entry(img).State = EntityState.Added;
                }

                var dbSizes = context.Sizes.Where(size => size.ProductItemId == entity.Id);
                if (!entity.Sizes.SequenceEqual(dbSizes.ToList()))
                {
                    context.Sizes.RemoveRange(dbSizes);
                    context.SaveChanges();
                    foreach (Size size in entity.Sizes)
                    {
                        context.Entry(size).State = EntityState.Added;
                    }
                }

                context.Entry(entity).State = EntityState.Modified;
                context.SaveChanges();
            }
            if (entity.Images.Any())
            {
                FileSystemApi.CopyTempDirectoryById(context.Entry(entity).Entity.Id);
            }
            context.SaveChanges();
        }
        }//end

        public void UpdateDistributor(Distributor distributor)
        {
            using (catalogDbContext = new CatalogDbContext())
            {
                var item = catalogDbContext.Distributors.Find(distributor.DistrId);
                if (item != null)
                {
                    catalogDbContext.Entry(item).CurrentValues.SetValues(distributor);
                    catalogDbContext.SaveChanges();
                }
            }
        }
 //Край на сегмента търсене---
 public void UpdateClient(Client client)
 {
     using (catalogDbContext = new CatalogDbContext())
     {
         var item = catalogDbContext.Clients.Find(client.Egn);
         if (item != null)
         {
             catalogDbContext.Entry(item).CurrentValues.SetValues(client);
             catalogDbContext.SaveChanges();
         }
     }
 }//end
        }//end

        public void DeleteDistributor(int distId)
        {
            using (catalogDbContext = new CatalogDbContext())
            {
                var distributor = catalogDbContext.Distributors.Find(distId);
                if (distributor != null)
                {
                    catalogDbContext.Distributors.Remove(distributor);
                    catalogDbContext.SaveChanges();
                }
            }
        }
        }//end

        public void DeleteProduct(int number)
        {
            using (catalogDbContext = new CatalogDbContext())
            {
                var product = catalogDbContext.Products.Find(number);
                if (product != null)
                {
                    catalogDbContext.Products.Remove(product);
                    catalogDbContext.SaveChanges();
                }
            }
        }//end
 //Изтриване на Клиенти, Дистрибутори, Продукти
 public void DeleteClient(string egn)
 {
     using (catalogDbContext = new CatalogDbContext())
     {
         var client = catalogDbContext.Clients.Find(egn);
         if (client != null)
         {
             catalogDbContext.Clients.Remove(client);
             catalogDbContext.SaveChanges();
         }
     }
 }//end
        }//end

        public void UpdateProduct(Product product)
        {
            using (catalogDbContext = new CatalogDbContext())
            {
                var item = catalogDbContext.Products.Find(product.Number);
                if (item != null)
                {
                    catalogDbContext.Entry(item).CurrentValues.SetValues(product);
                    catalogDbContext.SaveChanges();
                }
            }
        }//end
Exemple #9
0
        public static void InitializeDbForTests(CatalogDbContext catalogDbContext)
        {
            catalogDbContext.Playlists.RemoveRange(catalogDbContext.Playlists);
            catalogDbContext.Playlists.AddRange(CreatePlaylists());

            catalogDbContext.Tracks.RemoveRange(catalogDbContext.Tracks);
            catalogDbContext.Tracks.AddRange(CreateTracks());

            catalogDbContext.PlaylistTracks.RemoveRange(catalogDbContext.PlaylistTracks);
            catalogDbContext.PlaylistTracks.AddRange(CreatePlaylistTracks());

            catalogDbContext.SaveChanges();
        }
Exemple #10
0
 public void SaveCategory(Category entity)
 {
     if (entity != null)
     {
         if (entity.Image == null)
         {
             var categoty = GetCategoryById(entity.Id);
             entity.Image = categoty.Image;
         }
     }
     context.Entry(entity).State = EntityState.Modified;
     context.SaveChanges();
 }
Exemple #11
0
        public void A_Product_Sku_Can_Be_Verified_Unique()
        {
            var sku = "ABC-123";

            _catalogDbContext.Products.Add(new Product {
                Sku = sku
            });
            _catalogDbContext.SaveChanges();

            var result = _validator.IsSkuUnique(sku);

            Assert.That(result, Is.False);
        }
Exemple #12
0
        public BooksControllerTest()
        {
            _dbOptions = new DbContextOptionsBuilder <CatalogDbContext>()
                         .UseInMemoryDatabase("inmemory").Options;

            using var ctx = new CatalogDbContext(_dbOptions);
            ctx.Database.EnsureDeleted();

            var authors = GetFakeAuthorsCatalog();

            ctx.Authors.AddRange(authors);
            var books = GetFakeBooksCatalog();

            ctx.Books.AddRange(books);
            AssignFakeBookAuthorCatalogToBooks(authors, books);
            ctx.SaveChanges();
        }
Exemple #13
0
        /// <summary>
        /// Registers the new shard.
        /// Verify if shard exists for the tenant. If not then create new shard and add tenant details to Tenants table in catalog
        /// </summary>
        /// <param name="tenantName">Name of the tenant.</param>
        /// <param name="tenantId">The tenant identifier.</param>
        /// <param name="tenantServer">The tenant server.</param>
        /// <returns></returns>
        public static bool RegisterNewShard(int tenantId, string tenantName, string tenantServer, bool needToSaveOnDB = false)
        {
            try
            {
                ShardLocation shardLocation = new ShardLocation(tenantServer, tenantName);

                if (!ShardMap.TryGetShard(shardLocation, out Shard shard))
                {
                    //create shard if it does not exist
                    shard = ShardMap.CreateShard(shardLocation);
                }

                // Register the mapping of the tenant to the shard in the shard map.
                // After this step, DDR on the shard map can be used
                if (!ShardMap.TryGetMappingForKey(tenantId, out PointMapping <int> mapping))
                {
                    var pointMapping = ShardMap.CreatePointMapping(tenantId, shard);

                    if (needToSaveOnDB)
                    {
                        //convert from int to byte[] as tenantId has been set as byte[] in Tenants entity
                        var key = ShardHelper.ConvertIntKeyToBytesArray(pointMapping.Value);

                        //add tenant to Tenants table
                        var tenant = new Tenants
                        {
                            TenantId    = key,
                            TenantName  = tenantName,
                            LastUpdated = DateTime.Now
                        };

                        var db = new CatalogDbContext();
                        db.Tenants.Add(tenant);
                        db.SaveChanges();
                    }
                }

                return(true);
            }
            catch (Exception exception)
            {
                Trace.TraceError(exception.Message, "Error in registering new shard.");
                return(false);
            }
        }
Exemple #14
0
        public async Task <ResponseDTO> EditUser(UserDTO userDTO)
        {
            logger.LogInformation("Edit user in progress");

            var user = context.Users.Where(u => u.Id == userDTO.Id).SingleOrDefault();

            if (user == null)
            {
                return(new ResponseDTO()
                {
                    Code = 400,
                    Message = $"ApplicationUser with id {userDTO.Id} doesnt exists",
                    Status = "Error during add reservation"
                });
            }
            user.IsPaid       = userDTO.IsPaid;
            user.Email        = userDTO.Mail;
            user.UserName     = userDTO.Name;
            user.PasswordHash = userDTO.Password;
            user.PhoneNumber  = userDTO.Phone;

            try
            {
                context.ApplicationUsers.Update(user);
                context.SaveChanges();
            }
            catch (Exception e)
            {
                return(new ResponseDTO()
                {
                    Code = 400,
                    Message = e.Message,
                    Status = "error"
                });
            }
            return(new ResponseDTO()
            {
                Code = 200,
                Message = "User edited in db",
                Status = "Success"
            });
        }
Exemple #15
0
        // DELETE: Tenant
        public ActionResult Delete(string tenantName)
        {
            HttpContext.Server.ScriptTimeout = 600;

            tenantName = tenantName.ToLower();

            var db     = new CatalogDbContext();
            var tenant = db.Tenants.FirstOrDefault(t => t.TenantName == tenantName);

            if (tenant != null)
            {
                ShardHelper.DeleteTenantShard(DatabaseConfigHelper.GetServerNameFull(), tenantName);
                DeleteDb(tenantName);

                db.Tenants.Remove(tenant);
                db.SaveChanges();
            }

            return(RedirectToAction("List"));
        }
        public static CatalogDbContext Create()
        {
            var options = new DbContextOptionsBuilder <CatalogDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            var context = new CatalogDbContext(options);

            context.Categories.Add(new Api.Entities.Category()
            {
                Id   = 1,
                Code = "001",
                Name = "Lenovo Thinkpad"
            });
            context.SaveChanges();



            context.Database.EnsureCreated();

            return(context);
        }
 public static void InitializeDbForTests(CatalogDbContext context)
 {
     context.Categories.Add(new Category()
     {
         Id   = 1,
         Code = "001",
         Name = "Lenovo Thinkpad 1"
     });
     context.Categories.Add(new Category()
     {
         Id   = 2,
         Code = "002",
         Name = "Lenovo Thinkpad 2"
     });
     context.Categories.Add(new Category()
     {
         Id   = 3,
         Code = "003",
         Name = "Lenovo Thinkpad 3"
     });
     context.SaveChanges();
 }
Exemple #18
0
        public void OnActionExecuting(ActionExecutingContext context)
        {
            if (!string.IsNullOrWhiteSpace(currentUserService.UserId))
            {
                var customer = catalogDbContext
                               .Customers
                               .FirstOrDefault(x => x.UserId == currentUserService.UserId);

                if (customer == null)
                {
                    var newCustomer = new Customer
                    {
                        UserId = currentUserService.UserId
                    };

                    catalogDbContext
                    .Customers
                    .Add(newCustomer);

                    catalogDbContext
                    .SaveChanges();
                }
            }
        }
Exemple #19
0
 public void Insert(CatalogItemDto catalogItem)
 {
     _logger.LogTrace("Inserting new catalog item");
     _dbContext.Items.Add(catalogItem);
     _dbContext.SaveChanges();
 }
Exemple #20
0
 public void Insert(CatalogItemDto catalogItem)
 {
     _dbContext.Items.Add(catalogItem);
     _dbContext.SaveChanges();
 }
Exemple #21
0
        private void BeforeBackup()
        {
            IServiceContext serviceContext = ServiceContext.NewServiceContext(txtAdminUser.Text, "", "", txtOrg.Text, DataProtectInterface.TaskType.Catalog);
            serviceContext.CurrentMailbox = txtAdminUser.Text;
            var dataAccess = CatalogFactory.Instance.NewCatalogDataAccessInternal(serviceContext.Argument, serviceContext.AdminInfo.OrganizationName);
            dataAccess.ResetAllStorage(serviceContext.CurrentMailbox);

            if (!FactoryBase.IsRunningOnAzureOrStorageInAzure())
            {

                using (CatalogDbContext dbContext = new CatalogDbContext(new SqlDbImpl.Model.OrganizationModel() { Name = txtOrg.Text }))
                {
                    AppendToTextbox1(dbContext.Database.Connection.ConnectionString);
                    dbContext.Database.ExecuteSqlCommand("TRUNCATE TABLE CatalogInformation");
                    dbContext.Database.ExecuteSqlCommand("TRUNCATE TABLE MailboxInformation");
                    dbContext.Database.ExecuteSqlCommand("TRUNCATE TABLE ItemLocation");
                    dbContext.Database.ExecuteSqlCommand("TRUNCATE TABLE ItemInformation");
                    dbContext.Database.ExecuteSqlCommand("TRUNCATE TABLE FolderInformation");
                    dbContext.SaveChanges();
                }
            }
        }
 public void SaveCategoriesOfTheMonth(CategoriesOfTheMonth entity)
 {
     context.Entry(entity).State = EntityState.Modified;
     context.SaveChanges();
 }
Exemple #23
0
 public void Save()
 {
     _context.SaveChanges();
 }
 public void SaveDisplayedProducts(DisplayedProducts entity)
 {
     context.Entry(entity).State = EntityState.Modified;
     context.SaveChanges();
 }
Exemple #25
0
 public void Insert(CatalogCategoryDto category)
 {
     _dbContext.Categories.Add(category);
     _dbContext.SaveChanges();
 }