Пример #1
0
        /// <summary>
        /// Hàm dùng chung thêm mới dữ liệu vào 1 bảng
        /// </summary>
        /// <typeparam name="MISAEntity">Object của 1 bảng</typeparam>
        /// <param name="entity"></param>
        /// <returns>Số bản ghi bị ảnh hưởng</returns>
        /// CreatedBy:LCQUYEN(10/03/2021)
        public ServiceResult Insert <MISAEntity>(MISAEntity entity) where MISAEntity : BaseEntities
        {
            entity.EntityState = EntityState.AddNew;
            errorMsg           = new ErrorMsg();
            serviceResult      = new ServiceResult();
            //Thực hiện validate dữ liệu
            var isValidate = Validate <MISAEntity>(entity);

            if (isValidate != null && isValidate.Sussess == true)
            {
                var rowEffect = _baseRespository.Insert <MISAEntity>(entity);
                if (rowEffect > 0)
                {
                    errorMsg.devMsg        = Properties.Resources.Msg_AddSuccess;
                    errorMsg.userMsg       = Properties.Resources.Msg_AddSuccess;
                    serviceResult.Sussess  = true;
                    serviceResult.Data     = rowEffect;
                    serviceResult.MISACode = MISAConst.CreatedSuccess;
                    serviceResult.msg      = errorMsg;
                    return(serviceResult);
                }
                else
                {
                    errorMsg.devMsg        = Properties.Resources.ErrorMsg_NotRecordToDb;
                    errorMsg.userMsg       = Properties.Resources.ErrorMsg_NotRecordToDb;
                    serviceResult.Sussess  = false;
                    serviceResult.Data     = rowEffect;
                    serviceResult.MISACode = MISAConst.IsNotValid;
                    serviceResult.msg      = errorMsg;
                    return(serviceResult);
                }
            }
            else
            {
                return(isValidate);

                /* errorMsg.devMsg = Properties.Resources.ErrorMsg_NotRecordToDb;
                 * errorMsg.userMsg = Properties.Resources.ErrorMsg_NotRecordToDb;
                 * serviceResult.Sussess = false;
                 * serviceResult.MISACode = MISAConst.IsNotValid;
                 * serviceResult.msg = errorMsg;
                 * return serviceResult;*/
            }
        }
 private async Task InsertProduct(List <ProductEntity> throlledProductEntityObjects, string correlationToken)
 {
     await _productRepository.Insert(throlledProductEntityObjects, correlationToken);
 }
Пример #3
0
        public IActionResult CheckConnections()
        {
            var configurationState = string.Empty;

            var correlationToken = Guid.NewGuid().ToString();

            // Can I read UserSecrets and present configuration data
            configurationState = string.IsNullOrEmpty(configuration["ServiceBusPublisherConnectionString"]) ? "ServiceBus Connection string missing/n" : string.Empty;


            var serviceBusConnectionString = configuration["ServiceBusPublisherConnectionString"];
            var topicName        = configuration["ServiceBusTopicName"];
            var subscriptionName = configuration["ServiceBusSubscriptionName"];
            var storageAccount   = configuration["StorageAccount"];
            var storageKey       = configuration["StorageKey"];
            var storageTable     = configuration["StorageTableName_Basket"];

            var cosmosConnectionString = configuration["CosmosEndpoint"];
            var cosmosKey = configuration["CosmosPrimaryKey"];
            var databaseConnectonString = configuration["CatalogConnectionString"];


            var connectionString = configuration["ServiceBusPublisherConnectionString"];

            //var topicName = configuration["ServiceBusTopicName"];
            //var subscriptionName = configuration["ServiceBusSubscriptionName"];

            Guard.ForNullOrEmpty(connectionString, "ConnectionString from Catalog is Null");
            Guard.ForNullOrEmpty(topicName, "TopicName from Catalog is Null");
            Guard.ForNullOrEmpty(subscriptionName, "SubscriptionName from Catalog is Null");

            //Can I connect to the SqlDB and query products?

            var products = musicRepository.GetAll(correlationToken);

            if (products.Count < 1)
            {
                throw new Exception("Error in Seed Catalog Read Table -- Cannot get reference to the Products Table");
            }

            var productEntityObjects = products.Select(x => new ProductEntity
            {
                PartitionKey    = ProductPartitionKey,
                RowKey          = x.Id.ToString(),
                Title           = x.Title,
                ArtistName      = x.Artist.Name,
                Cutout          = x.Cutout,
                GenreName       = x.Genre.Name,
                ParentalCaution = x.ParentalCaution,
                Price           = x.Price.ToString(),
                ReleaseDate     = x.ReleaseDate,
                Upc             = x.Upc
            });

            try
            {
                var currentReadTableItems = productRepository.GetList(ProductPartitionKey).Result;
                var count = currentReadTableItems.Count();

                // Empty product read table
                for (var i = 0; i < count; i++)
                {
                    productRepository.Delete(currentReadTableItems[i].PartitionKey, currentReadTableItems[i].RowKey);
                }

                // Populate product read table
                foreach (var item in productEntityObjects)
                {
                    productRepository.Insert(item, correlationToken);
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"Could not build Catalog Read Table in DataInitializer. Message : {ex.Message}");
            }



            // Can I connect to Azure Storage and query on baskets?



            // Can I connect to Azure Service Bus and ensure that each Topic and subscription is present?



            // Can I connect to CosmosDB and query for orders?

            configurationState = "This feature is not enabled\n\n";

            return(Ok(configurationState));
        }