Пример #1
0
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                var file = Request.Files[0];

                string imgName     = System.IO.Path.GetFileName(file.FileName);
                string fisicalPath = Server.MapPath("~/images/" + imgName);
                file.SaveAs(fisicalPath);

                var product = new ASF.Entities.Product();
                product.Title       = collection["title"];
                product.Description = collection["description"];
                product.DealerId    = Int32.Parse(collection["dealerId"]);
                product.Price       = double.Parse(collection["price"]);
                product.Image       = imgName;
                product.CreatedOn   = DateTime.Now;
                product.ChangedOn   = DateTime.Now;

                productProcess.Add(product);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult Nuevo(Product form)
        {
            Artist artist = new Artist();

            //artist = _ap.Get(form.ArtistId);
            // uploaded image
            if (Request.Files.Count > 0)
            {
                var file = Request.Files[0];

                if (file != null && file.ContentLength > 0)
                {
                    var fileName = Path.GetFileName(file.FileName);
                    var path     = Path.Combine(Server.MapPath("~/Content/Img/Product"), fileName);
                    file.SaveAs(path);

                    form.Image = file.FileName;
                }
            }

            //form.Artist = artist;
            form.ChangedOn = DateTime.Now;
            form.CreatedOn = DateTime.Now;

            //CheckAuditPattern(product, true);
            _pp.Add(form);

            return(RedirectToAction("Index"));
        }
        public ActionResult Create([Bind(Include = "Id,Title,Description,DealerId,Image,Price,QuantitySold,AvgStars,Rowid,CreatedOn,CreatedBy,ChangedOn,ChangedBy")] Product product)
        {
            if (ModelState.IsValid)
            {
                productProcess.Add(product);

                return(RedirectToAction("Index"));
            }

            return(View(product));
        }