public async Task <IActionResult> EditHoraires(Guid etablissementId)
        {
            try
            {
                EditHoraireViewModel model    = new EditHoraireViewModel();
                List <Horaire>       lHoraire = await horaireService.GetAllHorairesAsync();

                lHoraire = lHoraire.Where(x => x.EtablissementId == etablissementId).ToList();

                if (lHoraire != null)
                {
                    List <string> lJours = new JoursSemaine().lJours;
                    lHoraire = lHoraire.OrderBy(h => lJours.IndexOf(h.Jour)).ThenBy(h => h.HeureOuverture).ToList();

                    model.lHoraire = lHoraire;
                }
                else
                {
                    model.lHoraire = new List <Horaire>();
                }
                model.EtablissementId = etablissementId;

                return(View(model));
            }
            catch (Exception ex)
            {
                ErrorViewModel vme = new ErrorViewModel()
                {
                    RequestId = ex.Message
                };
                return(View("Error", vme));
            }
        }
        public CreateEtablissementViewModel()
        {
            lTypeEtablissement = new TypeEtablissement().types;
            lPays          = new Pays().lPays;
            lJoursSemaines = new JoursSemaine().lJours;
            this.Etab      = new Etablissement();
            this.lHoraire  = new List <Horaire>();

            this.Photos = new PhotoGeneriqueViewModel[NombrePhotos];
            for (int i = 0; i < NombrePhotos; i++)
            {
                Photos[i] = new PhotoGeneriqueViewModel();
            }
        }
示例#3
0
        public void RunEnumerations()
        {
            // Afficheg du lzbrl
            Console.WriteLine($"JoursSemaine.Lundi = {JoursSemaine.Lundi}");
            // Afficher l'entier spis-jacent
            Console.WriteLine($"JoursSemaine.Lundi = {(int) JoursSemaine.Lundi}");
            // int > vers valeur d'enum
            int          day4      = 4;
            JoursSemaine whoIsday4 = (JoursSemaine)day4;

            Console.WriteLine($"day = {whoIsday4}");
            // String > valeur d'enum
            string       mardi  = "Mardi";
            JoursSemaine parsed = (JoursSemaine)Enum.Parse(
                typeof(JoursSemaine),
                mardi);

            Console.WriteLine($"parsed = {parsed}");
            // .Net Core / .Net > 4
            // JoursSemaine parsed2;
            // bool didItWork = Enum.TryParse("Mercredi", out parsed2);
            // C # 7
            bool didItWork = Enum.TryParse(mardi, out JoursSemaine parsed2);

            Console.WriteLine($"parsed2 = {parsed2} / worked ? {didItWork}");
            // Enumérer les labels
            var enumNames  = Enum.GetNames((typeof(JoursSemaine))); // string []
            var enumValues = Enum.GetValues(typeof(JoursSemaine));  // JoursSemaine[] sous-typé

            foreach (var enumName in enumNames)
            {
                Console.WriteLine(enumName);
            }
            foreach (JoursSemaine enumValue in enumValues)
            {
                Console.WriteLine((int)enumValue);
            }

            var       jour = (JoursSemaine)(new Random().Next(0, 7));
            DayOfWeek foundDayOfWeek;

            switch (jour)
            {
            case JoursSemaine.Lundi:
                foundDayOfWeek = DayOfWeek.Monday;
                break;

            case JoursSemaine.Mardi:
                foundDayOfWeek = DayOfWeek.Tuesday;
                break;

            case JoursSemaine.Mercredi:
                foundDayOfWeek = DayOfWeek.Wednesday;
                break;

            case JoursSemaine.Jeudi:
                foundDayOfWeek = DayOfWeek.Thursday;
                break;

            case JoursSemaine.Vendredi:
                foundDayOfWeek = DayOfWeek.Friday;
                break;

            case JoursSemaine.Samedi:
                foundDayOfWeek = DayOfWeek.Saturday;
                break;

            case JoursSemaine.Dimanche:
                foundDayOfWeek = DayOfWeek.Sunday;
                break;

            default:
                foundDayOfWeek = DayOfWeek.Sunday;
                break;
            }
            // Console.WriteLine($"Random day was {foundDayOfWeek}");
            // C#7 : nameof() => nom de la variable, en string
            Console.WriteLine($"{nameof(foundDayOfWeek)} = {foundDayOfWeek}");
        }
 public EditEtablissementViewModel()
 {
     lTypeEtablissement = new TypeEtablissement().types;
     lPays          = new Pays().lPays;
     lJoursSemaines = new JoursSemaine().lJours;
 }
 public EditHoraireViewModel()
 {
     lHoraire = new List <Horaire>();
     lJours   = new JoursSemaine().lJours;
 }