/// <summary>
 /// Delete record of the barcode in the repository.
 /// </summary>
 /// <param name="barcode">Barcode model.</param>
 public void Delete(BarcodeDB barcode)
 {
     if (barcode != null)
     {
         _wasteContext.Barcodes.Remove(barcode);
     }
     _wasteContext.SaveChanges();
 }
        /// <summary>
        /// Update record of the barcode in the repository.
        /// </summary>
        /// <param name="barcode">New barcode to Update.</param>
        public async Task UpdateAsync(BarcodeDB barcode)
        {
            _wasteContext.Entry(barcode).State = EntityState.Modified;
            var barcodeDB = await _wasteContext.Barcodes.FirstOrDefaultAsync(b => b.Id == barcode.Id);

            barcodeDB.Modified = DateTime.UtcNow;
            await _wasteContext.SaveChangesAsync().ConfigureAwait(false);
        }
        /// <summary>
        /// Add new barcode in the repository.
        /// </summary>
        /// <param name="barcode">New barcode to add.</param>
        /// <returns>Barcode Id.</returns>
        public async Task <string> AddAsync(BarcodeDB barcode)
        {
            barcode.Id      = Guid.NewGuid().ToString();
            barcode.Created = DateTime.UtcNow;
            _wasteContext.Barcodes.Add(barcode);

            await _wasteContext.SaveChangesAsync().ConfigureAwait(false);

            return(barcode.Id);
        }
示例#4
0
        public void Init()
        {
            barcode = new Barcode
            {
                Id          = Guid.NewGuid().ToString(),
                Code        = "456731556",
                ProductName = "Some product"
            };
            barcodeDB = new BarcodeDB
            {
                Id   = Guid.NewGuid().ToString(),
                Code = "456731556"
            };

            selectedList = new List <ProductDB>();

            mapConfig = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <Product, ProductDB>()
                .ForMember(m => m.Created,
                           opt => opt.MapFrom(p => p.Name != null ? DateTime.UtcNow : default(DateTime)))
                .ForMember(m => m.Modified, opt => opt.UseValue((DateTime?)null))
                .ForMember(m => m.Barcode, opt => opt.Ignore())
                .ReverseMap();
                cfg.AddProfile <CategoryProfile>();
            });

            mapper = new Mapper(mapConfig);

            mockProductRepository  = new Mock <IProductRepository>();
            mockCategoryRepository = new Mock <ICategoryRepository>();
            mockBarcodeService     = new Mock <IBarcodeService>();

            category = new Category
            {
                Id          = new Guid().ToString(),
                Name        = "Vegetables",
                Description = "Some description"
            };

            product = new Product {
                Id = new Guid().ToString(), Name = "Some name"
            };
            productDB = new ProductDB {
                Id = new Guid().ToString(), Name = "Some name"
            };
            categoryDB = new CategoryDB {
                Id = new Guid().ToString(), Name = "Some name"
            };
        }
 /// <summary>
 /// Update record of the barcode in the repository.
 /// </summary>
 /// <param name="barcode">New barcode to Update.</param>
 public void Update(BarcodeDB barcode)
 {
     _wasteContext.Entry(barcode).State = EntityState.Modified;
     _wasteContext.Barcodes.First(i => i.Id == barcode.Id).Modified = DateTime.UtcNow;;
     _wasteContext.SaveChanges();
 }
 /// <summary>
 /// Add new barcode in the repository.
 /// </summary>
 /// <param name="barcode">New barcode to add.</param>
 public void Add(BarcodeDB barcode)
 {
     barcode.Created = DateTime.UtcNow;
     _wasteContext.Barcodes.Add(barcode);
     _wasteContext.SaveChanges();
 }