コード例 #1
0
        public static ProductDemand[] GetSalesHistory()
        {
            var result   = new List <ProductDemand>();
            var textFile = File.OpenText(@"files\\sales-jan-mar-2017.csv");

            textFile.ReadLine();
            var line = textFile.ReadLine();

            while (line != null)
            {
                var parts = line.Split(',');
                var pd    = new ProductDemand();
                pd.Locationid    = int.Parse(parts[1]);
                pd.RecipeName    = parts[2];
                pd.Plu           = int.Parse(parts[3]);
                pd.Salesdate     = DateTime.Parse(parts[4]);
                pd.Quantity      = float.Parse(parts[5]);
                pd.NetSalesPrice = float.Parse(parts[6]);
                pd.CostPrice     = float.Parse(parts[7]);
                pd.Year          = int.Parse(parts[8]);
                pd.Month         = int.Parse(parts[9]);
                pd.Day           = int.Parse(parts[10]);
                pd.WeekDay       = int.Parse(parts[11]);
                pd.YearDay       = int.Parse(parts[12]);
                result.Add(pd);

                line = textFile.ReadLine();
            }
            return(result.ToArray());
        }
コード例 #2
0
 private Dictionary <string, string> CreatePayload(ProductDemand productDemand)
 {
     return(new Dictionary <string, string>()
     {
         { "Locationid", productDemand.Locationid.ToString() },
         { "RecipeName", productDemand.RecipeName },
         { "PLU", productDemand.Plu.ToString() },
         { "Salesdate", productDemand.Salesdate.ToString("s") },
         { "Quantity", productDemand.Quantity.ToString() },
         { "NetSalesPrice", productDemand.NetSalesPrice.ToString() },
         { "CostPrice", productDemand.CostPrice.ToString() },
         { "Year", productDemand.Year.ToString() },
         { "Month", productDemand.Month.ToString() },
         { "Day", productDemand.Day.ToString() },
         { "WeekDay", productDemand.WeekDay.ToString() },
         { "YearDay", productDemand.YearDay.ToString() }
     });
 }
コード例 #3
0
ファイル: ProductManager.cs プロジェクト: SKarakayaa/perdecim
        public async Task <IResult> UpdateProduct(UpdateProductDto productDto)
        {
            Product product = await _productDAL.GetAsync(x => x.Id == productDto.Id);

            product.BrandId      = productDto.BrandId;
            product.CanNotable   = productDto.CanNotable;
            product.CategoryId   = productDto.CategoryId;
            product.Description  = productDto.Description;
            product.DiscountRate = productDto.DiscountRate;
            product.InStock      = productDto.InStock;
            product.IsNew        = productDto.IsNew;
            product.IsPopular    = productDto.IsPopular;
            product.Name         = productDto.Name;
            product.Price        = productDto.Price;

            _productDAL.Update(product);

            List <ProductColor> productColors = await _productColorDAL.GetListAsyncTracked(x => x.ProductId == productDto.Id);

            for (int i = 0; i < productColors.Count; i++)
            {
                if (i <= productDto.ColorIds.Count() - 1)
                {
                    productColors[i].ColorId = productDto.ColorIds[i];
                    _productColorDAL.Update(productColors[i]);
                }
                else
                {
                    _productColorDAL.Remove(productColors[i]);
                }
            }

            if (productDto.DemandTypeIds != null && productDto.DemandTypeIds.Count() != 0)
            {
                List <ProductDemand> productDemands = await _productDemandDAL.GetListAsync(x => x.ProductId == productDto.Id);

                List <ProductDemand> removedDemands = productDemands.Where(x => !productDto.DemandTypeIds.Contains(x.DemandTypeId)).ToList();
                foreach (var demandTypeId in productDto.DemandTypeIds)
                {
                    bool isExist = productDemands.Any(x => x.DemandTypeId == demandTypeId);
                    if (!isExist)
                    {
                        _productDemandDAL.Add(new ProductDemand(product.Id, demandTypeId));
                    }

                    ProductDemand isRemove = removedDemands.Count > 0 ? removedDemands.FirstOrDefault(x => x.DemandTypeId == demandTypeId) : null;
                    if (isRemove != null)
                    {
                        _productDemandDAL.Remove(isRemove);
                    }
                }
            }

            if (productDto.Images != null && productDto.Images.Count() > 0)
            {
                foreach (var image in productDto.Images)
                {
                    string imageName  = Guid.NewGuid() + "." + image.FileName.Split('.')[1];
                    var    fileLocate = $"{productDto.FilePath}/{imageName}";
                    product.ProductImages.Add(new ProductImage {
                        ImageName = imageName, ProductId = product.Id
                    });

                    using (var stream = new FileStream(fileLocate, FileMode.Create))
                    {
                        image.CopyTo(stream);
                    }
                }
            }

            int result = await _uow.Complete();

            return(ResultHelper <int> .ResultReturn(result));
        }