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 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);
        }
        public async Task <int> DeleteAsync(int id)
        {
            RO_Garment deletedImage = await this.ReadByIdAsync(id);

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

            await this.AzureDocumentFacade.RemoveMultipleFile(deletedImage.GetType().Name, deletedImage.DocumentsPath);

            await roGarmentLogic.DeleteAsync(id);

            int deleted = await DbContext.SaveChangesAsync();

            await DeletedROCostCalAsync(deletedImage.CostCalculationGarment, (int)deletedImage.CostCalculationGarmentId);

            return(deleted);
        }
        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);

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

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

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

            return(updated);
        }
Example #5
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);
        }
Example #6
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));
        }