Ejemplo n.º 1
0
        public async Task AddProductPackDates()
        {
            var product = new SimsProduct
            {
                Name              = "Product PackDates no sizes with dates",
                BatchCodes        = "BC1234 BC59867",
                Brand             = "New Brand",
                HostId            = 21,
                CountryOfOriginId = 103,
                Amount            = "7",
                ProductTypeId     = 2,
                AmountUnitTypeId  = 1,
                AdditionalInfo    = "More Data needed",
                PackDescription   = "This is description",
                ProductDates      = new List <SimsProductDate>()
                {
                    new SimsProductDate {
                        Date = DateTime.Now, DateTypeId = 2
                    },
                    new SimsProductDate {
                        Date = DateTime.Now, DateTypeId = 3
                    }
                }
            };

            using (var ctx = SeedingConfigData.GetDbContext(this.conn))
            {
                var simsHost       = SimsDbHost.CreateHost(ctx, this.mapper, this.userId);
                var updatedProduct = await simsHost.Signals.Products.Add(product.HostId, product);

                Assert.True(updatedProduct.ProductDates.Count() > 0);
            }
        }
Ejemplo n.º 2
0
        public async Task AddProductNoCollections()
        {
            var newName = "Product no collections";
            var product = new SimsProduct
            {
                Name              = newName,
                BatchCodes        = "BC1234 BC59867",
                Brand             = "New Brand",
                HostId            = 21,
                CountryOfOriginId = 103,
                Amount            = "7",
                ProductTypeId     = 2,
                AmountUnitTypeId  = 1,
                AdditionalInfo    = "Signal Data",
                PackDescription   = "This is descirption",
            };

            using (var ctx = SeedingConfigData.GetDbContext(this.conn))
            {
                var simsHost       = SimsDbHost.CreateHost(ctx, this.mapper, this.userId);
                var updatedProduct = await simsHost.Signals.Products.Add(product.HostId, product);

                Assert.True(updatedProduct.Name == newName);
            }
        }
Ejemplo n.º 3
0
        public async Task AddProductPackSizesDefaultAmount()
        {
            var product = new SimsProduct
            {
                Name              = "Product Pack Sizes no dates with sizes",
                BatchCodes        = "BC New packers BNA2324",
                Brand             = "A Brand",
                HostId            = 17,
                CountryOfOriginId = 47,
                ProductTypeId     = 2,
                Amount            = "0.0",
                AmountUnitTypeId  = 3,
                AdditionalInfo    = "More Data needed",
                PackDescription   = "This is description",
                PackSizes         = new List <SimsProductPackSize>
                {
                    new SimsProductPackSize {
                        Size = "7", UnitId = 2
                    },
                    new SimsProductPackSize {
                        Size = "18.8", UnitId = 2
                    },
                }
            };

            using (var ctx = SeedingConfigData.GetDbContext(this.conn))
            {
                var simsHost       = SimsDbHost.CreateHost(ctx, this.mapper, this.userId);
                var updatedProduct = await simsHost.Signals.Products.Add(product.HostId, product);

                Assert.True(updatedProduct.PackSizes.Count() == 2 && updatedProduct.Amount == "0.0");
            }
        }
Ejemplo n.º 4
0
        public async Task <SimsProduct> Add(int HostId, SimsProduct newProduct)
        {
            if (HostId == 0)
            {
                throw new ArgumentOutOfRangeException("No host selected.");
            }
            var dbItem = mapper.Map <SimsProduct, T>(newProduct);

            dbItem.HostId = HostId;
            var dbCreated = DbSet.Add(dbItem);
            await ctx.SaveChangesAsync();

            return(mapper.Map <T, SimsProduct>(dbCreated.Entity));
        }
 public async Task <SimsProduct> Add(int hostId, SimsProduct newSimsProduct)
 {
     if (hostId == 0)
     {
         throw new SimsIncidentMissingException("Incident missing");
     }
     if (!await dbHost.Incidents.IsClosed(hostId))
     {
         return(await dbHost.Incidents.Products.Add(hostId, newSimsProduct));
     }
     else
     {
         throw new SimsIncidentClosedException("Incident closed");
     }
 }
Ejemplo n.º 6
0
        public async Task <SimsProduct> Update(SimsProduct product)
        {
            var productDb = this.DbSet
                            .Include(o => o.ProductType)
                            .Include(o => o.PackSizes)
                            .First(p => p.Id == product.Id);

            var pDates = this.DbSetDates.Where(i => i.ProductId == product.Id).ToList();

            mapper.Map(product, productDb);

            var updatedEnt = this.DbSet.Update(productDb);
            await ctx.SaveChangesAsync();

            return(mapper.Map <T, SimsProduct>(updatedEnt.Entity));
        }
        public async Task <SimsProduct> Update(SimsProduct SimsProduct)
        {
            if (SimsProduct.Id == 0)
            {
                throw new SimsItemMissing("Missing id");
            }
            var product = await dbHost.Incidents.Products.Get(SimsProduct.Id);

            if (!await dbHost.Incidents.IsClosed(product.HostId))
            {
                return(await dbHost.Incidents.Products.Update(SimsProduct));
            }
            else
            {
                throw new SimsIncidentClosedException("Incident closed");
            }
        }
        public async Task <SimsProduct> Update(SimsProduct product)
        {
            if (product.Id == 0)
            {
                throw new SimsItemMissing("Missing id");
            }
            var appProduct = await dbHost.Signals.Products.Get(product.Id);

            if (!await dbHost.Signals.IsClosed((int)appProduct.HostId))
            {
                return(await dbHost.Signals.Products.Update((SimsProduct)product));
            }
            else
            {
                throw new SimsSignalClosedException("Signal closed");
            }
        }
        public async Task AddProductOnlineForm()
        {
            var factCheck     = "Add new Prodcuts";
            var newOnlineForm = this.BasicForm();

            newOnlineForm.Title = factCheck;

            var product = new SimsProduct
            {
                Added             = DateTime.Parse("01/01/2000"),
                AdditionalInfo    = "Additional product infor",
                BatchCodes        = "Big string of data",
                AmountUnitTypeId  = 21,
                Amount            = "15",
                ProductTypeId     = 22,
                Brand             = "Product Brand",
                CountryOfOriginId = 90,
                Name      = "The faulty product",
                PackSizes = new[] { new SimsProductPackSize {
                                        Size = "21", UnitId = 1
                                    } },
                PackDescription = "The is the description of the product.",
                ProductDates    = new[] { new SimsProductDate {
                                              Date = DateTime.Parse("15/03/27"), DateTypeId = 2
                                          } }
            };

            using (var ctx = SeedingConfigData.GetDbContext(this.conn))
            {
                var simsHost  = SimsDbHost.CreateHost(ctx, this.mapper, this.userId);
                var savedForm = await simsHost.OnlineForms.Add(newOnlineForm);

                var newProduct = await simsHost.OnlineForms.Products.Add(savedForm.CommonId, product);

                Assert.True(savedForm.Title == factCheck);
            }
        }
 public async Task <SimsProduct> Add(int hostId, SimsProduct newSimsProduct)
 {
     return(await dbHost.OnlineForms.Products.Add(hostId, newSimsProduct));
 }