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");
        }
Exemple #2
0
 public void deleteAnimal(AnimalModel animal)
 {
     bdd.animals.Remove(animal);
 }
Exemple #3
0
 void IDal.addAdvertissement(DateTime date_param, string title_param, string description_param, AnimalModel animal_param, string userId)
 {
     bdd.advertissements.Add(new AdvertisementModel { date = date_param, title = title_param, description = description_param, animal = animal_param, UserId = userId });
     // persister les modifications en base de données
     bdd.SaveChanges();
 }
Exemple #4
0
 public int addAnimal(AnimalModel animal)
 {
     bdd.animals.Add(new AnimalModel { name = animal.name, race = animal.race, type = animal.type, photo = animal.photo });
     return bdd.SaveChanges();
 }