コード例 #1
0
ファイル: CatalogueService.cs プロジェクト: harshsgit/Cordoba
        public int InsertUpdateCatalogue(int StoreId, int LoggedInUserId, CatalogueEntity catalogueEntity)
        {
            var catalogueIdparam = new SqlParameter
            {
                ParameterName = "catalogue_Id",
                DbType        = DbType.Int32,
                Value         = catalogueEntity.catalogue_Id
            };

            var nameparam = new SqlParameter
            {
                ParameterName = "Name",
                DbType        = DbType.String,
                Value         = catalogueEntity.Name
            };

            var paramStoreId = new SqlParameter
            {
                ParameterName = "StoreId",
                DbType        = DbType.Int32,
                Value         = StoreId
            };

            var paramLoggedInUserId = new SqlParameter
            {
                ParameterName = "LoggedInUserIdId",
                DbType        = DbType.Int32,
                Value         = LoggedInUserId
            };
            var result = objGenericRepository.ExecuteSQL <int>("InsertUpdateCatalogue", catalogueIdparam, nameparam, paramStoreId, paramLoggedInUserId).FirstOrDefault();

            return(result);
        }
コード例 #2
0
ファイル: CatalogueService.cs プロジェクト: harshsgit/Cordoba
        public CatalogueEntity GetCatalogueById(int StoreId, int LoggedInUserId, int CatalogueId = 0)
        {
            CatalogueEntity ProductCatalogueEntity = new CatalogueEntity();

            if (CatalogueId > 0)
            {
                var paramCatalogueId = new SqlParameter
                {
                    ParameterName = "CatalogueId",
                    DbType        = DbType.Int32,
                    Value         = CatalogueId
                };
                var paramStoreId = new SqlParameter
                {
                    ParameterName = "StoreId",
                    DbType        = DbType.Int32,
                    Value         = StoreId
                };
                var paramLoggedInUserId = new SqlParameter
                {
                    ParameterName = "LoggedInUserIdId",
                    DbType        = DbType.Int32,
                    Value         = LoggedInUserId
                };
                var result = objGenericRepository.ExecuteSQL <CatalogueEntity>("GetCatalogueById", paramCatalogueId, paramStoreId, paramLoggedInUserId).FirstOrDefault();
                ProductCatalogueEntity = result;
            }
            else
            {
                ProductCatalogueEntity = new CatalogueEntity();
            }

            return(ProductCatalogueEntity);
        }
コード例 #3
0
        public void GetProducts()
        {
            var options = new DbContextOptionsBuilder <DataContext>()
                          .UseInMemoryDatabase("GetProduct_Exists").Options;

            //Given
            var catalgue = new CatalogueEntity {
                Id = Guid.NewGuid(), Name = "Sports"
            };
            var product1 = new ProductEntity {
                Id = Guid.NewGuid(), Name = "Golf Clubs", CatalogueId = catalgue.Id
            };
            var product2 = new ProductEntity {
                Id = Guid.NewGuid(), Name = "Soccer Ball", CatalogueId = catalgue.Id
            };

            var product3 = new ProductEntity {
                Id = Guid.NewGuid(), Name = "Book", CatalogueId = Guid.NewGuid()
            };

            using (var context = new DataContext(options))
            {
                context.Catalogue.Add(catalgue);

                context.Product.Add(product1);
                context.Product.Add(product2);

                context.SaveChanges();
            }

            using (var context = new DataContext(options))
            {
                var service = new ProductService(context);

                //When
                var list = service.GetProducts(catalgue.Id);

                //Then
                Assert.Equal(2, list.Count);

                var actual1 = list[0];
                Assert.Equal(product1.Id, actual1.Id);
                Assert.Equal(product1.Name, actual1.Name);
                Assert.Equal(catalgue.Id, actual1.CatalogueId);
                Assert.Equal(catalgue.Name, actual1.CatalogueName);

                var actual2 = list[1];
                Assert.Equal(product2.Id, actual2.Id);
                Assert.Equal(product2.Name, actual2.Name);
                Assert.Equal(catalgue.Id, actual2.CatalogueId);
                Assert.Equal(catalgue.Name, actual2.CatalogueName);
            }
        }
コード例 #4
0
        public void GetProduct()
        {
            var options = new DbContextOptionsBuilder <DataContext>()
                          .UseInMemoryDatabase("GetProduct").Options;

            //Given
            var catalgue = new CatalogueEntity {
                Id = Guid.NewGuid(), Name = "Sports"
            };
            var product1 = new ProductEntity {
                Id = Guid.NewGuid(), Name = "Golf Clubs", CatalogueId = catalgue.Id
            };
            var product2 = new ProductEntity {
                Id = Guid.NewGuid()
            };

            using (var context = new DataContext(options))
            {
                context.Catalogue.Add(catalgue);

                context.Product.Add(product2);
                context.Product.Add(product1);

                context.SaveChanges();
            }

            using (var context = new DataContext(options))
            {
                var service = new ProductService(context);

                //When
                var actual = service.GetProduct(product1.Id);

                //Then
                Assert.Equal(product1.Id, actual.Id);
                Assert.Equal(product1.Name, actual.Name);
                Assert.Equal(catalgue.Id, actual.CatalogueId);
                Assert.Equal(catalgue.Name, actual.CatalogueName);
            }
        }
コード例 #5
0
 public HttpResponseMessage InsertUpdateCatalogue(int StoreId, int LoggedInUserId, CatalogueEntity catalogueEntity)
 {
     try
     {
         var result = _catalogueServices.InsertUpdateCatalogue(StoreId, LoggedInUserId, catalogueEntity);
         if (result >= -1)
         {
             return(Request.CreateResponse(HttpStatusCode.OK, result));
         }
         return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Something wrong! Please try again later."));
     }
     catch (Exception)
     {
         throw;
     }
 }