Beispiel #1
0
        public ListeRestaurantVue(TypeCuisine leTypeCuisine)
        {
            ListeRestaurantVueModele vuesModeles;

            InitializeComponent();
            BindingContext = vuesModeles = new ListeRestaurantVueModele(leTypeCuisine);
        }
Beispiel #2
0
        public ActionResult Create([Bind(Include = "IdTypeCuisine,Nom,Statut")] TypeCuisine typeCuisine, HttpPostedFileBase file)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (file.ContentLength > 0 && file.ContentLength < 2500000)
                    {
                        if (Functions.IsImage(file))
                        {
                            var fileName = Path.GetFileName(file.FileName);
                            var pathBDD  = "Images/Upload/" + fileName;
                            var path     = Path.Combine(Server.MapPath("~/Images/Upload"), fileName);
                            file.SaveAs(path);
                            Afpetit.Models.Photo photo = new Photo();
                            photo.Nom    = fileName;
                            photo.Statut = true;
                            photo.Url    = pathBDD;

                            typeCuisine.Photos.Add(photo);
                            db.TypeCuisines.Add(typeCuisine);

                            db.SaveChanges();
                        }
                    }
                }
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
                return(View(typeCuisine));
            }
        }
Beispiel #3
0
        //Bouton sauver
        private void buttonTypeCuisine_Click(object sender, EventArgs e)
        {
            //Création d'un objet TypeCuisine avec l'id à -1 (création) ou >0 (passé en paramètre)
            //Les autres propriétés viennent des textBoxes
            TypeCuisine t = new TypeCuisine();

            t.id   = this.typeCuisineId;
            t.type = textBoxTypeCuisine.Text;
            //si pas de description, remplissage avec un texte prédéfini
            if (richTextBoxDescType.Text.Length == 0)
            {
                t.description = "Aucune description pour ce type de cuisine.";
            }
            else
            {
                t.description = richTextBoxDescType.Text;
            }
            //Si Validate renvoie true, l'objet est valide et peut être transmis à la BU pour traitement
            if (Validate(t))
            {
                //Si id = -1 alors c'est une création, envoi à la BU (TypeCuisineManager.Create)
                if (typeCuisineId == -1)
                {
                    TypeCuisineManager.Create(t);
                }
                //Sinon c'est une modification, envoi à la BU (TypeCuisineManager.Update)
                else
                {
                    TypeCuisineManager.Update(t);
                }
                //Fermeture du form
                this.Dispose();
            }
        }
Beispiel #4
0
 //constructeur du form avec paramètre (Modification typeCuisine), hérite du constructeur par défaut
 public FormTypeCuisine(TypeCuisine typeCuisine) : this()
 {
     //Initialisation de l'id et des textBoxes avec les valeurs transmises
     this.typeCuisineId = typeCuisine.id;
     textBoxTypeCuisine.DataBindings.Add("Text", typeCuisine, "type");
     richTextBoxDescType.DataBindings.Add("Text", typeCuisine, "description");
 }
Beispiel #5
0
        public ActionResult DeleteConfirmed(int id)
        {
            TypeCuisine typeCuisine = db.TypeCuisines.Find(id);

            db.TypeCuisines.Remove(typeCuisine);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #6
0
 public ActionResult Edit([Bind(Include = "IdTypeCuisine,Nom,Statut")] TypeCuisine typeCuisine)
 {
     if (ModelState.IsValid)
     {
         db.Entry(typeCuisine).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(typeCuisine));
 }
Beispiel #7
0
        //Modifier Type de Cuisine
        private void buttonModType_Click(object sender, EventArgs e)
        {
            int         id          = (int)dataGridViewTypesCuisine.SelectedRows[0].Cells[0].Value;
            TypeCuisine typeCuisine = TypeCuisineManager.GetAll().Find(x => x.id == id);

            if (id > 0)
            {
                FormTypeCuisine f = new FormTypeCuisine(typeCuisine);
                f.ShowDialog();
                PopulateGrids();
            }
        }
Beispiel #8
0
        private bool Validate(TypeCuisine t)
        {
            //Initialisation de la couleur des labels à "par défaut"
            labelTypeCuisine.ForeColor     = Color.Empty;
            labelDescriptionType.ForeColor = Color.Empty;
            bool   valid   = true;
            string message = "";

            //Si le nom du type fait moins de 3
            if (t.type.Length < 3)
            {
                labelTypeCuisine.ForeColor = Color.Red;
                valid    = false;
                message += "Le nom du type doit au moins faire 3 caractères.\n";
            }
            //Si le nom du type contient autre chose que des caractères et des espaces
            if (!Regex.IsMatch(t.type, @"^[a-zA-Z ]+$"))
            {
                labelTypeCuisine.ForeColor = Color.Red;
                valid    = false;
                message += "Le nom du type ne doit contenir que des caractères alphabétiques.\n";
            }
            //Si le nom du type existe déjà
            if (TypeCuisineManager.GetAll().Find(x => x.type == t.type) != null)
            {
                //Si c'est un ajout OU que l'id du type modifié est différent de l'id du type existant
                if ((this.typeCuisineId == -1) || (this.typeCuisineId != TypeCuisineManager.GetAll().Find(x => x.type == t.type).id))
                {
                    labelTypeCuisine.ForeColor = Color.Red;
                    valid    = false;
                    message += "Le type existe déjà.\n";
                }
            }
            //Si la description fait moins de 10 (préremplie si vide)
            if (t.description.Length < 10)
            {
                labelDescriptionType.ForeColor = Color.Red;
                valid    = false;
                message += "La description doit être vide ou faire au moins 10 caractères.\n";
            }
            //Si le TypeCuisine envoyé par le form est invalide
            if (!valid)
            {
                //Affichage du message d'erreur
                string            caption = "Erreur";
                MessageBoxButtons buttons = MessageBoxButtons.OK;
                MessageBoxIcon    icon    = MessageBoxIcon.Error;
                MessageBox.Show(message, caption, buttons, icon);
            }
            //retourne valid
            return(valid);
        }
Beispiel #9
0
        // GET: TypeCuisines/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TypeCuisine typeCuisine = db.TypeCuisines.Find(id);

            if (typeCuisine == null)
            {
                return(HttpNotFound());
            }
            return(View(typeCuisine));
        }
Beispiel #10
0
        //Obtention de tous les TypeCuisine
        public static List <TypeCuisine> GetAll()
        {
            //Obtention de la dataTable
            OdawaDS.typescuisineDataTable dt = DataProvider.GetTypesCuisine();
            //Création d'une liste vide
            List <TypeCuisine> lst = new List <TypeCuisine>();

            //Pour chaque restaurant dans la dataTable
            foreach (OdawaDS.typescuisineRow typeRow in dt.Rows)
            {
                TypeCuisine t = new TypeCuisine();
                t.id          = typeRow.id;
                t.type        = typeRow.type;
                t.description = typeRow.description;
                //Ajout à la liste
                lst.Add(t);
            }
            //Retourne la liste
            return(lst);
        }
Beispiel #11
0
 //Création TypeCuisine avec l'objet "t" passé en paramètre
 public static bool Create(TypeCuisine t)
 {
     //Création d'une typescuisineRow et remplissage avec les attributs de "t"
     OdawaDS.typescuisineRow newRow = DataProvider.odawa.typescuisine.NewtypescuisineRow();
     newRow.type        = t.type;
     newRow.description = t.description;
     //Envoi à la DAL
     try
     {
         DataProvider.CreateTypeCuisine(newRow);
         //Si création ok, renvoie true
         return(true);
     }
     catch (System.Data.SqlClient.SqlException ex)
     {
         //si SqlException, log et renvoie false
         LogManager.LogSQLException(ex.Message);
         return(false);
     }
 }
Beispiel #12
0
 //Mise à jour d'un TypeCuisine "t" passé en paramètre
 public static bool Update(TypeCuisine t)
 {
     OdawaDS.typescuisineDataTable dt = DataProvider.GetTypesCuisine();
     //Création d'une typescuisineRow et remplissage avec les attributs de "t"
     OdawaDS.typescuisineRow updRow = DataProvider.odawa.typescuisine.NewtypescuisineRow();
     updRow.id          = t.id;
     updRow.type        = t.type;
     updRow.description = t.description;
     //Envoi à la DAL
     try
     {
         DataProvider.UpdateTypeCuisine(updRow);
         //Si update ok, renvoie true
         return(true);
     }
     catch (System.Data.SqlClient.SqlException ex)
     {
         //Si SqlException, log et renvoie false
         LogManager.LogSQLException(ex.Message);
         return(false);
     }
 }
Beispiel #13
0
 List<Restaurants> RestaurantsDAO.findRestaurantsByType(TypeCuisine t)
 {
     throw new NotImplementedException();
 }
Beispiel #14
0
 public ListeRestaurantVueModele(TypeCuisine leTypeCuisine)
 {
     NomTypeCuisine = string.Concat("Le type cuisine : ", leTypeCuisine.Libelle);
     LesRestaurants = new ObservableCollection <Restaurant>(leTypeCuisine.LesRestaurants);
 }