public ActionResult Create()
        {
            VentureContext db = new VentureContext();

            ViewBag.AgentSelect = new SelectList(db.Agents, "AgentId", "FullName");
            return(View());
        }
        // GET: listing
        public ActionResult Index()
        {
            VentureContext db       = new VentureContext();
            List <Listing> listings = db.Listings.ToList();

            foreach (Listing listing in listings)
            {
                listing.ImgPath = db.Images.Where(i => i.ListingId == listing.ListingId)
                                  .FirstOrDefault().Path;
            }
            return(View(listings));
        }
        public ActionResult Create(Listing listing, HttpPostedFileBase[] files)
        {
            VentureContext db = new VentureContext();

            if (ModelState.IsValid)
            {
                listing.AgentId = Convert.ToInt32(Request.Form["AgentSelect"]);
                db.Listings.Add(listing);
                db.SaveChanges();


                foreach (HttpPostedFileBase fileBase in files)
                {
                    if (!string.Equals(fileBase.ContentType, "image/jpg", StringComparison.OrdinalIgnoreCase) &&
                        !string.Equals(fileBase.ContentType, "image/jpeg", StringComparison.OrdinalIgnoreCase) &&
                        !string.Equals(fileBase.ContentType, "image/pjpeg", StringComparison.OrdinalIgnoreCase) &&
                        !string.Equals(fileBase.ContentType, "image/gif", StringComparison.OrdinalIgnoreCase) &&
                        !string.Equals(fileBase.ContentType, "image/x-png", StringComparison.OrdinalIgnoreCase) &&
                        !string.Equals(fileBase.ContentType, "image/png", StringComparison.OrdinalIgnoreCase))
                    {
                        ViewBag.Error = "The file is not an image";
                        return(View());
                    }
                    else
                    {
                        string path = Path.Combine(Server.MapPath("~\\Uploads"),
                                                   Path.GetFileName(fileBase.FileName));
                        fileBase.SaveAs(path);
                        Image img = new Image()
                        {
                            Approved  = true,
                            ListingId = listing.ListingId,
                            Name      = Path.GetFileName(path),
                            Path      = Path.Combine("..\\..\\Uploads", Path.GetFileName(path))
                        };
                        db.Images.Add(img);
                        db.SaveChanges();
                        ViewBag.Message = "File uploaded successfully";
                    }
                }

                return(RedirectToAction("Index", "ListingManage"));
            }

            ViewBag.AgentSelect = new SelectList(db.Agents, "AgentId", "FullName");
            return(View(listing));
        }
Пример #4
0
        public ActionResult Index(Login login)
        {
            VentureContext db = new VentureContext();
            // Query for the Blog named ADO.NET Blog
            Login loginMatch = db.Logins
                               .Where(l => l.Username == login.Username && l.Password == login.Password)
                               .FirstOrDefault();

            if (loginMatch == null)
            {
                ViewBag.Error = "Username and/or Password incorrect. Try again.";
                return(View());
            }

            Session.Add("username", loginMatch.Username);
            Session.Add("role", loginMatch.RoleId);

            return(RedirectToAction("Index", "Home"));
        }