Exemplo n.º 1
0
        public async Task <bool> AddRangeAsync(List <IngredientForImportExcelDto> model)
        {
            var ingredients = _mapper.Map <List <Ingredient> >(model);

            _repoIngredient.AddRange(ingredients);
            return(await _repoIngredient.SaveAll());
        }
Exemplo n.º 2
0
        public async Task <string> AddRangeAsync(List <IngredientForImportExcelDto> model)
        {
            var suppliers = await _repoSupplier.FindAll().ToListAsync();

            var    ingredientList = _repoIngredient.FindAll();
            string error          = string.Empty;

            foreach (var item in model)
            {
                var checkMaterial = ingredientList.FirstOrDefault(x => x.MaterialNO.Equals(item.MaterialNO));
                var checkName     = ingredientList.FirstOrDefault(x => x.Name.Equals(item.Name));
                if (checkMaterial != null)
                {
                    error = $"Material# {item.MaterialNO} already exists in the database";
                    break;
                }
                if (checkName != null)
                {
                    error = $"Ingredient Name {item.Name} already exists in the database";
                    break;
                }
            }
            if (error != string.Empty)
            {
                return(error);
            }
            model.ForEach(item =>
            {
                item.isShow     = true;
                var supply      = suppliers.FirstOrDefault(x => x.Name.ToLower().Equals(item.SupplierName.ToSafetyString().ToLower()));
                item.SupplierID = supply != null ? supply.ID : 0;
            });
            var ingredients = _mapper.Map <List <Ingredient> >(model);

            _repoIngredient.AddRange(ingredients);
            try
            {
                await _repoIngredient.SaveAll();

                return("ok");
            }
            catch
            {
                return("Error");
            }
        }