public async Task <int> CreateAsync(RO_Garment Model)
        {
            do
            {
                Model.Code = Code.Generate();
            }while (this.DbSet.Any(d => d.Code.Equals(Model.Code)));

            CostCalculationGarment costCalculationGarment = await costCalGarmentLogic.ReadByIdAsync((int)Model.CostCalculationGarment.Id); //Model.CostCalculationGarment;

            foreach (var item in costCalculationGarment.CostCalculationGarment_Materials)
            {
                foreach (var itemModel in Model.CostCalculationGarment.CostCalculationGarment_Materials)
                {
                    if (item.Id == itemModel.Id)
                    {
                        item.Information = itemModel.Information;
                    }
                }
            }
            Model.CostCalculationGarment = null;

            roGarmentLogic.Create(Model);
            int created = await DbContext.SaveChangesAsync();

            Model.ImagesPath = await AzureImageFacade.UploadMultipleImage(Model.GetType().Name, (int)Model.Id, Model.CreatedUtc, Model.ImagesFile, Model.ImagesPath);

            Model.DocumentsPath = await AzureDocumentFacade.UploadMultipleFile(Model.GetType().Name, (int)Model.Id, Model.CreatedUtc, Model.DocumentsFile, Model.DocumentsFileName, Model.DocumentsPath);

            await UpdateCostCalAsync(costCalculationGarment, (int)Model.Id);

            return(created);
        }
        public void UpdateAsync_Return_Success()
        {
            string           testName        = GetCurrentMethod();
            var              dbContext       = _dbContext(testName);
            IIdentityService identityService = new IdentityService {
                Username = "******"
            };
            var model = new RO_Garment()
            {
                Code = "Code",
                RO_Garment_SizeBreakdowns = new List <RO_Garment_SizeBreakdown>()
                {
                    new RO_Garment_SizeBreakdown()
                    {
                        Id        = 1,
                        ColorName = "red"
                    },
                },
                CostCalculationGarment = new CostCalculationGarment(),
            };

            dbContext.RO_Garments.Add(model);
            dbContext.SaveChanges();
            ROGarmentLogic unitUnderTest = new ROGarmentLogic(GetServiceProvider(testName).Object, identityService, dbContext);

            unitUnderTest.UpdateAsync(model.Id, model);
        }
        public async Task <RO_Garment> ReadByIdAsync(int id)
        {
            RO_Garment read = await this.DbSet
                              .Where(d => d.Id.Equals(id) && d.IsDeleted.Equals(false))
                              .Include(d => d.RO_Garment_SizeBreakdowns)
                              .ThenInclude(sb => sb.RO_Garment_SizeBreakdown_Details)
                              .Include(d => d.CostCalculationGarment)
                              .ThenInclude(ccg => ccg.CostCalculationGarment_Materials)
                              .FirstOrDefaultAsync();

            read.RO_Garment_SizeBreakdowns = read.RO_Garment_SizeBreakdowns.OrderBy(o => o.SizeBreakdownIndex).ToList();
            foreach (var sizeBreakdown in read.RO_Garment_SizeBreakdowns)
            {
                sizeBreakdown.RO_Garment_SizeBreakdown_Details = sizeBreakdown.RO_Garment_SizeBreakdown_Details.OrderBy(o => o.SizeBreakdownDetailIndex).ToList();
            }

            read.CostCalculationGarment.ImageFile = await this.AzureImageFacade.DownloadImage(read.CostCalculationGarment.GetType().Name, read.CostCalculationGarment.ImagePath);

            read.ImagesFile = await this.AzureImageFacade.DownloadMultipleImages(read.GetType().Name, read.ImagesPath);

            if (!string.IsNullOrWhiteSpace(read.DocumentsPath))
            {
                read.DocumentsFile = await AzureDocumentFacade.DownloadMultipleFiles(read.GetType().Name, read.DocumentsPath);
            }

            return(read);
        }
Пример #4
0
        public async Task <int> DeleteAsync(int id)
        {
            RO_Garment deletedImage = await this.ReadByIdAsync(id);

            await this.AzureImageFacade.RemoveMultipleImage(deletedImage.GetType().Name, deletedImage.ImagesPath);

            await roGarmentLogic.DeleteAsync(id);

            await DbContext.SaveChangesAsync();

            return(await DeletedROCostCalAsync(deletedImage.CostCalculationGarment, (int)deletedImage.CostCalculationGarmentId));
        }
Пример #5
0
        public async Task <int> UpdateAsync(int id, RO_Garment Model)
        {
            CostCalculationGarment costCalculationGarment = Model.CostCalculationGarment;

            Model.CostCalculationGarment = null;

            Model.ImagesPath = await this.AzureImageFacade.UploadMultipleImage(Model.GetType().Name, (int)Model.Id, Model.CreatedUtc, Model.ImagesFile, Model.ImagesPath);

            roGarmentLogic.UpdateAsync(id, Model);
            await DbContext.SaveChangesAsync();

            return(await UpdateCostCalAsync(costCalculationGarment, (int)Model.Id));
        }
Пример #6
0
        public async Task <RO_Garment> ReadByIdAsync(int id)
        {
            RO_Garment read = await this.DbSet
                              .Where(d => d.Id.Equals(id) && d.IsDeleted.Equals(false))
                              .Include(d => d.RO_Garment_SizeBreakdowns)
                              .ThenInclude(sb => sb.RO_Garment_SizeBreakdown_Details)
                              .Include(d => d.CostCalculationGarment)
                              .ThenInclude(ccg => ccg.CostCalculationGarment_Materials)
                              .FirstOrDefaultAsync();

            read.CostCalculationGarment.ImageFile = await this.AzureImageFacade.DownloadImage(read.CostCalculationGarment.GetType().Name, read.CostCalculationGarment.ImagePath);

            read.ImagesFile = await this.AzureImageFacade.DownloadMultipleImages(read.GetType().Name, read.ImagesPath);

            return(read);
        }
Пример #7
0
        public void Mapping_With_AutoMapper_Profiles()
        {
            var configuration = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile <ROGarmentMapper>();
                cfg.AddProfile <ROGarmentSizeBreakdownMapper>();
                cfg.AddProfile <ROGarmentSizeBreakdownDetailMapper>();
            });
            var mapper = configuration.CreateMapper();

            RO_GarmentViewModel vm = new RO_GarmentViewModel {
                Id = 1
            };
            RO_Garment model = mapper.Map <RO_Garment>(vm);

            Assert.Equal(vm.Id, model.Id);
        }
Пример #8
0
        public async Task PostRO_Throws_Exception()
        {
            var dbContext           = DbContext(GetCurrentMethod());
            var serviceProviderMock = new Mock <IServiceProvider>();

            Mock <IIdentityService> identityService = new Mock <IIdentityService>();

            identityService.Setup(s => s.Username).Throws(new Exception());

            serviceProviderMock
            .Setup(x => x.GetService(typeof(IIdentityService)))
            .Returns(identityService.Object);

            ROGarmentSizeBreakdownLogic roGarmentSizeBreakdownLogic = new ROGarmentSizeBreakdownLogic(serviceProviderMock.Object, identityService.Object, dbContext);

            serviceProviderMock
            .Setup(x => x.GetService(typeof(ROGarmentSizeBreakdownLogic)))
            .Returns(roGarmentSizeBreakdownLogic);

            ROGarmentLogic roGarmentLogic = new ROGarmentLogic(serviceProviderMock.Object, identityService.Object, dbContext);

            serviceProviderMock
            .Setup(x => x.GetService(typeof(ROGarmentLogic)))
            .Returns(roGarmentLogic);

            RO_Garment garment = new RO_Garment()
            {
                Id = 1
            };

            dbContext.RO_Garments.Add(garment);
            dbContext.SaveChanges();

            ROGarmentFacade facade = new ROGarmentFacade(serviceProviderMock.Object, dbContext);

            await Assert.ThrowsAsync <Exception>(() => facade.PostRO(new List <long> {
                1
            }));
        }
Пример #9
0
        public async Task <int> CreateAsync(RO_Garment Model)
        {
            do
            {
                Model.Code = Code.Generate();
            }while (this.DbSet.Any(d => d.Code.Equals(Model.Code)));

            CostCalculationGarment costCalculationGarment = await costCalGarmentLogic.ReadByIdAsync((int)Model.CostCalculationGarment.Id); //Model.CostCalculationGarment;

            Model.CostCalculationGarment = null;

            Model.ImagesPath = await this.AzureImageFacade.UploadMultipleImage(Model.GetType().Name, (int)Model.Id, Model.CreatedUtc, Model.ImagesFile, Model.ImagesPath);

            roGarmentLogic.Create(Model);
            await DbContext.SaveChangesAsync();

            //Model.ImagesPath = await this.AzureImageService.UploadMultipleImage(Model.GetType().Name, Model.Id, Model._CreatedUtc, Model.ImagesFile, Model.ImagesPath);

            //await this.UpdateAsync((int)Model.Id, Model);
            //update CostCal

            return(await UpdateCostCalAsync(costCalculationGarment, (int)Model.Id));
        }