Ejemplo n.º 1
0
        public ActionResult Create([Bind(Include = "ID,Description,phone")] AdTable adTable, HttpPostedFileBase image1, HttpPostedFileBase image2) //ttpPostedFileBase image was new
        {
            try
            {
                if (image1 == null && image2 == null)
                {
                    db.AdTable.Add(adTable);
                    db.SaveChanges();
                    return(RedirectToAction("Index", "AdTables"));
                }

                else if (image1 == null && image2 != null)
                {
                    ViewBag.Ms = "Please upload image #1 first";
                    return(View());
                }

                else if (CreateHelper.pictureNotImage1(image1))
                {
                    ViewBag.Ms = "Only Image can be uploaded";
                    return(View());
                }

                else if (image1 != null && image2 == null)
                {
                    adTable.image = new byte[image1.ContentLength];
                    image1.InputStream.Read(adTable.image, 0, image1.ContentLength);
                    db.AdTable.Add(adTable);
                    db.SaveChanges();
                    return(RedirectToAction("Index", "AdTables"));
                }

                else if (CreateHelper.pictureNotImage(image1, image2)
                         )
                {
                    ViewBag.Ms = "Only Image can be uploaded";
                    return(View());
                }

                else if (ModelState.IsValid)
                {
                    adTable.image = new byte[image1.ContentLength];
                    image1.InputStream.Read(adTable.image, 0, image1.ContentLength);
                    adTable.image1 = new byte[image2.ContentLength];
                    image2.InputStream.Read(adTable.image1, 0, image2.ContentLength);
                    db.AdTable.Add(adTable);
                    db.SaveChanges();
                    return(RedirectToAction("Index", "AdTables"));
                }
            }
            catch
            {
                ViewBag.Ms = "Only Images can be uploaded";
                return(View());
            }
            return(View(adTable));
        }
Ejemplo n.º 2
0
        public ActionResult Create([Bind(Include = "ID,Description,phone,price")] ForRent forRent, HttpPostedFileBase image1, HttpPostedFileBase image2)
        {
            try {
                //{    //Check if Description already exist in database
                //    var y = forRent.Description.ToLower();
                //    List<ForRent> a = db.ForRent.Where(x => x.Description.ToLower() == y).ToList();
                //    if (a.Capacity > 0)
                //    {
                //        ViewBag.Ms = "Element already exist";
                //        return View();
                //    }


                if (image1 == null && image2 == null)
                {
                    db.ForRent.Add(forRent);
                    db.SaveChanges();
                    return(RedirectToAction("Index", "ForRents"));
                }
                else if (image1 == null && image2 != null)
                {
                    ViewBag.Ms = "Please upload image #1 first";
                    return(View());
                }
                else if (CreateHelper.pictureNotImage1(image1))
                {
                    ViewBag.Ms = "Only Image can be uploaded";
                    return(View());
                }

                else if (image1 != null && image2 == null)
                {
                    forRent.image = new byte[image1.ContentLength];
                    image1.InputStream.Read(forRent.image, 0, image1.ContentLength);
                    db.ForRent.Add(forRent);
                    db.SaveChanges();
                    return(RedirectToAction("Index", "ForRents"));
                }
                else if (CreateHelper.pictureNotImage(image1, image2)
                         )
                {
                    ViewBag.Ms = "Only Image can be uploaded";
                    return(View());
                }


                else if (ModelState.IsValid)
                {
                    forRent.image = new byte[image1.ContentLength];
                    image1.InputStream.Read(forRent.image, 0, image1.ContentLength);

                    forRent.image1 = new byte[image2.ContentLength];
                    image2.InputStream.Read(forRent.image1, 0, image2.ContentLength);

                    db.ForRent.Add(forRent);
                    db.SaveChanges();
                    return(RedirectToAction("Index", "ForRents"));
                }
            }

            catch
            {
                return(View());
            }

            return(View(forRent));
        }