示例#1
0
        public ActionResult Create(CreateNewProductVM np)
        {
            try
            {
                ///creating product
                ProductBiz     productBiz = new ProductBiz();
                List <Company> lst        = new List <Company>();
                Product        product    = new Product();


                product.Name       = np.ProductName;
                product.Versions   = np.Versions;
                product.CompanyId  = np.CompanyId;
                product.Components = np.Components;

                productBiz.CreateProduct(product);

                np.Compaines = productBiz.GetCompanies();
                ModelState.AddModelError("PM", "Product created successfully");
                return(View(np));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#2
0
        // Create new product with image
        private bool InsertProduct()
        {
            objProduct    = new Product();
            objProductBiz = new ProductBiz();

            HttpPostedFile postedFile    = flProductImage.PostedFile;
            string         fileName      = Path.GetFileName(postedFile.FileName);
            string         fileExtension = Path.GetExtension(fileName);
            int            fileSize      = postedFile.ContentLength;

            if (fileExtension.ToLower() == ".jpg" || fileExtension.ToLower() == ".png" || fileExtension.ToLower() == ".bmp" || fileExtension.ToLower() == ".gif")
            {
                if (fileSize > 524288)
                {
                    MessageBox("Image size should not be more than 512 Kbps");
                }
                else
                {
                    Stream       stream       = postedFile.InputStream;
                    BinaryReader binaryReader = new BinaryReader(stream);
                    byte[]       bytes        = binaryReader.ReadBytes((int)stream.Length);
                    objProduct.ProductImageName = fileName;
                    objProduct.ProductImageSize = fileSize;
                    objProduct.ProductImage     = bytes;

                    objProduct.ProductName        = txtProductName.Text.Trim();
                    objProduct.ProductDescription = txtProductDescription.Text.Trim();
                    objProduct.RegionId           = Convert.ToByte(ddlRegion.SelectedItem.Value);
                    objProduct.FirstCategoryId    = Convert.ToInt16(ddlFirstCategory.SelectedItem.Value);
                    objProduct.SecondCategoryId   = Convert.ToInt16(ddlSecondCategory.SelectedItem.Value);
                    objProduct.ThirdCategoryId    = Convert.ToInt16(ddlThirdCategory.SelectedItem.Value);
                    objProduct.BrandId            = Convert.ToInt16(ddlBrand.SelectedItem.Value);
                    objProduct.MeasurementId      = Convert.ToByte(ddlMeasurement.SelectedItem.Value);
                    objProduct.ProductSellPrice   = Convert.ToDecimal(txtSellPrice.Text.Trim());
                    objProduct.Vat            = Convert.ToDecimal(txtVatOnProduct.Text.Trim());
                    objProduct.FoodScheduleId = Convert.ToByte(ddlFoodSchedule.SelectedItem.Value);
                    objProduct.CreatedBy      = Convert.ToInt16(Session["UserId"]);

                    MessageBox(objProductBiz.CreateProduct(objProduct));
                }
            }
            else
            {
                MessageBox("Please upload valid (jpg, png, gif & bmp) picture");
            }

            return(true);
        }