Ejemplo n.º 1
0
        public ActionResult NewPostings(NewPostingsModel model)
        {
            model.Categories = categoryManager.SelectAllCategoriesForNewPostings();
            if (ModelState.IsValid)
            {
                string image = "";
                foreach (var posting in model.Image)
                {
                    if (posting != null)
                    {
                        if (posting.ContentLength > 0)
                        {
                            if (Path.GetExtension(posting.FileName).ToLower() == ".jpg" ||
                                Path.GetExtension(posting.FileName).ToLower() == ".png" ||
                                Path.GetExtension(posting.FileName).ToLower() == ".gif" ||
                                Path.GetExtension(posting.FileName).ToLower() == ".jpeg")
                            {
                                string random = DateTime.Now.ToString("yyyyMMdd_HHmmssfff");
                                string path   = Path.Combine(Server.MapPath("~/Content/Images"), random + posting.FileName);
                                posting.SaveAs(path);

                                path   = "~/Content/Images/" + random + posting.FileName;
                                image += path + ";";
                            }
                        }
                    }
                }
                manager.CreateNewPostings(model.CategoryId, model.Title, model.Price, model.Adress, image, model.Phone, model.Email, model.Description, Session.GetUser().Id);
                TempData["Success"] = "Sludinājums ir pievienots!";
                return(RedirectToAction("NewPostings"));
            }
            return(View(model));
        }
Ejemplo n.º 2
0
        //Get: NewPostings
        public ActionResult NewPostings()
        {
            NewPostingsModel model = new NewPostingsModel();

            model.Categories = categoryManager.SelectAllCategoriesForNewPostings();

            return(View(model));
        }