コード例 #1
0
        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");
        }
コード例 #2
0
ファイル: Dal.cs プロジェクト: PetCareIAGL/Petcare
 public void deleteAnimal(AnimalModel animal)
 {
     bdd.animals.Remove(animal);
 }
コード例 #3
0
ファイル: Dal.cs プロジェクト: PetCareIAGL/Petcare
 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();
 }
コード例 #4
0
ファイル: Dal.cs プロジェクト: PetCareIAGL/Petcare
 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();
 }