Exemplo n.º 1
0
        public ActionResult LoadProductDetails(Guid id)
        {
            ProductDetailRepository pdRepo = new ProductDetailRepository();

            return

                (Json(pdRepo.GetProductDetailsByProduct(id), JsonRequestBehavior.AllowGet));//returneaza un json-lista de orase – prin GET
        }
Exemplo n.º 2
0
 public AddProduct()
 {
     InitializeComponent();
     productRepository         = new ProductRepository();
     categoryRepository        = new CategoryRepository();
     entityAttributeRepository = new EntityAttributeRepository();
     productCategoryRepository = new ProductCategoryRepository();
     productDetailRepository   = new ProductDetailRepository();
 }
        /// <summary>
        /// apply your validations inside the method
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        private ExcelUploadResponseModel ApplyValidation(DataTable data)
        {
            IRepository <Product> productRepository = new ProductRepository(_unitOfWork);
            IRepository <Packet>  packetRepsitory   = new PacketRepository(_unitOfWork);

            List <ErrorMessageModel> errorMessageModels = new List <ErrorMessageModel>();

            if (data == null)
            {
                throw new InvalidOperationException();
            }

            // performing the validation here

            if (data.Rows.Count == 0)
            {
                throw new IndexOutOfRangeException();
            }

            var products = productRepository.GetAll();
            var packets  = packetRepsitory.GetAll();

            var inputData = data.ToListof <InputDataModelV1>();
            int row       = 0;
            int count     = inputData.Count();

            List <ProductDetail> productDetailsList = new List <ProductDetail>();

            inputData.RemoveAll((inputModel) =>
            {
                bool canDelete        = false;
                var errorMessageModel = new ErrorMessageModel(row);
                var packet            = packets.FirstOrDefault(p => p.PacketCode.Equals(inputModel.Packet, StringComparison.InvariantCultureIgnoreCase));
                if (packet == null)
                {
                    errorMessageModel.ErrorMessagees.Add($" Row {row}, packet code {inputModel.Packet} does not exists");
                    canDelete = true;
                }
                var product = products.FirstOrDefault(p => p.ProductCode.Equals(inputModel.Product, StringComparison.InvariantCultureIgnoreCase));
                if (product == null)
                {
                    errorMessageModel.ErrorMessagees.Add($" Row {row}, product code {inputModel.Packet} does not exists");
                    canDelete = true;
                }

                row++;
                if (canDelete)
                {
                    errorMessageModels.Add(errorMessageModel);
                }
                else
                {
                    productDetailsList.Add(new ProductDetail
                    {
                        ProductId = product.ProductId,
                        PacketId  = packet.PacketId
                                    //add the other values over here
                    });
                }

                return(canDelete);
            });

            if (productDetailsList.Count() == count)
            {
                IRepository <ProductDetail> productDetailrepository = new ProductDetailRepository(_unitOfWork);

                productDetailsList.ForEach(detaiils =>
                {
                    productDetailrepository.Insert(detaiils);
                });
                _unitOfWork.SaveChanges();
                return(new ExcelUploadResponseModel(null));
            }

            return(new ExcelUploadResponseModel(errorMessageModels));
            //save functionality here
        }