Beispiel #1
0
        public ActionResult Index()
        {
            // méthode retournant un resultat de type ViewResult dérivé de ActionResult
            // elle doit contenir le nom de la vue à rendre. Par default si c'est pas présé on recherche la vue avec le meme nom que l'action

            using (IDal dal = new Dal())
            {
                //dal.addAdvertissement(DateTime.Now, "Chien méchant", "La description", null);
                //List<AdvertisementModel> advertissements = dal.getAllAdvertissements();

                //ViewBag.Message = "Titre = " + advertissements[0].title;
            }
            return View();
        }
 public ActionResult ConsultAdvertisementView()
 {
     IDal dal = new Dal();
     List<AdvertisementModel> advertissements = dal.getAllAdvertissements();
     return View(advertissements);
 }
        public ActionResult RegisterAdvertisement(AdvertisementModel model, HttpPostedFileBase file)
        {
            if (Request.IsAuthenticated)
            {
                if (ModelState.IsValid)
                {
                    string userId = User.Identity.GetUserId();

                    //animal
                    AnimalModel animal = new AnimalModel
                    {
                        name = model.animal.race,
                        type = model.animal.type,
                        race = model.animal.race
                    };

                    if (file != null)
                    {
                        _imageController = new ImageController();
                        animal.photo = new List<ImageModel> { _imageController.GetImage(file) };
                    }

                    using (IDal dal = new Dal())
                        dal.addAdvertissement(DateTime.Now, model.title, model.description, animal, userId);

                    return RedirectToAction("RegisterAdvertisement", new { Message = AdvertisementMessageId.AddAdvertiseSuccess });
                }
                else
                    return View(model);
            }
            else
                return RedirectToAction("Login", "Account");
        }
        public PartialViewResult Load(HttpPostedFileBase file)
        {
            if (file != null)
            {
                _imageController = new ImageController();
                //get the bytes from the uploaded file
                byte[] data = _imageController.GetBytesFromFile(file);

                using (IDal dal = new Dal())
                {
                    dal.addImage(data, "");
                }
            }

            return PartialView();
        }