Ejemplo n.º 1
0
        // GET: Ticket/Create
        public async System.Threading.Tasks.Task <ActionResult> Acheter()
        {
            TicketViewModels ticketViewModels = new TicketViewModels();

            ticketViewModels.nbTicket = 0;
            IdentityModels userIdentity = await UserManager.FindByEmailAsync(User.Identity.Name);

            if (userIdentity != null)
            {
                var cartes = userIdentity.CarteModels;
                if (cartes != null && cartes.Count > 0)
                {
                    CarteModels carte = cartes.ElementAt(0);
                    if (carte.TicketModels != null)
                    {
                        ticketViewModels.nbTicket = (uint)carte.TicketModels.Count;
                        if (carte.TicketModels.Count > 0)
                        {
                            TicketModels ticket = carte.TicketModels.First();
                            ticketViewModels.prixTicket = ticket.TarifModels.prix;
                        }
                        else
                        {
                            double prix = bdd.TarifModels.ToList().Find(t => t.type.Contains("ticket")).prix;
                            ticketViewModels.prixTicket = prix;
                        }
                    }
                }
            }
            return(View(ticketViewModels));
        }
Ejemplo n.º 2
0
 public ActionResult Index()
 {
     try
     {
         HomeViewModels homeViewModel = new HomeViewModels();
         //nbTicket
         CarteModels carte    = carteRepository.findCarteByUser(User.Identity.Name);
         int         nbTicket = carte.TicketModels.Count;
         homeViewModel.nbTicket = nbTicket;
         //abonnement souscrit
         int nbAboSouscrit = carte.AbonnementsModels.Count;
         homeViewModel.nbAbo = nbAboSouscrit;
         var           enumAbo      = carte.AbonnementsModels.GetEnumerator();
         List <string> intituleList = new List <string>();
         while (enumAbo.MoveNext())
         {
             AbonnementModels item        = enumAbo.Current;
             int idType                   = item.TypeAbonnementModelsID;
             TypeAbonnementModels typeAbo = Context.TypeAbonnementModels.Find(idType);
             intituleList.Add(typeAbo.Intitule);
         }
         homeViewModel.intituleList = intituleList;
         return(View(homeViewModel));
     }
     catch (Exception e)
     {
         HomeViewModels homeView = new HomeViewModels();
         homeView.nbTicket     = 0;
         homeView.nbAbo        = 0;
         homeView.intituleList = new List <string>();
         return(View(homeView));
     }
 }
Ejemplo n.º 3
0
        // GET: Abonnement/Create
        public ActionResult Souscrire()
        {
            AbonnementViewModels aboViewModels = new AbonnementViewModels();
            var allTypeAbonnement = bdd.TypeAbonnementModels.Include("TarifModels");

            aboViewModels.TypeAbo        = allTypeAbonnement.ToList();
            aboViewModels.TypeAboPossede = new List <TypeAbonnementModels>();
            CarteModels             carteUser   = carte.findCarteByUser(User.Identity.Name);
            List <AbonnementModels> aboUserList = carteUser.AbonnementsModels.ToList();

            if (aboUserList != null)
            {
                foreach (AbonnementModels abo in aboUserList)
                {
                    int typeAboId = abo.TypeAbonnementModelsID;
                    TypeAbonnementModels typeAbo = bdd.TypeAbonnementModels.Find(typeAboId);
                    if (typeAbo != null)
                    {
                        string intitule = typeAbo.Intitule;
                        aboViewModels.TypeAboPossede.Add(typeAbo);
                        aboViewModels.TypeAbo.Remove(typeAbo);
                    }
                }
            }
            return(View(aboViewModels));
        }
Ejemplo n.º 4
0
        public async System.Threading.Tasks.Task <ActionResult> Acheter(TicketViewModels ticketvm)
        {
            try
            {
                uint           nbTicketSurLaCarte = 0;
                IdentityModels userIdentity       = await UserManager.FindByEmailAsync(User.Identity.Name);

                if (userIdentity != null)
                {
                    var         cartes = userIdentity.CarteModels;
                    CarteModels carte  = cartes.ElementAt(0);
                    nbTicketSurLaCarte = (uint)carte.TicketModels.Count;
                    if (carte != null)
                    {
                        ICollection <TicketModels> ticketList;
                        if (carte.TicketModels == null)
                        {
                            ticketList = new List <TicketModels>();
                        }
                        else
                        {
                            ticketList = carte.TicketModels;
                        }
                        for (int i = 0; i < ticketvm.nbTicket; i++)
                        {
                            TicketModels ticket = new TicketModels();
                            ticket.CarteModelsID = carte.Id;
                            int tarifId = bdd.TarifModels.ToList().Find(t => t.type.Contains("ticket")).Id;
                            ticket.TarifModelsID = tarifId;
                            ticketList.Add(ticket);
                            bdd.TicketModels.Add(ticket);
                        }
                        //carte.TicketModels = ticketList;
                        // bdd.CarteModels.Add(carte);
                        bdd.SaveChanges();
                    }
                }
                ticketvm.nbTicket   = (uint)ticketvm.nbTicket + nbTicketSurLaCarte;
                ticketvm.prixTicket = bdd.TarifModels.Find(3).prix;
                //return RedirectToAction("Index");
                return(View(ticketvm));
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Trace.TraceInformation("Property: {0} Error: {1}",
                                               validationError.PropertyName,
                                               validationError.ErrorMessage);
                    }
                }
                return(View(ticketvm));
            }
        }
Ejemplo n.º 5
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var         userStore   = new UserStore <IdentityModels>(db);
                    var         userManager = new UserManager <IdentityModels>(userStore);
                    CarteModels carte       = new CarteModels {
                    };
                    carte.dateCreation = DateTime.Today;
                    var user = new IdentityModels {
                        UserName = model.Email, Email = model.Email
                    };
                    user.CarteModels.Add(carte);
                    var result = await UserManager.CreateAsync(user, model.Password);

                    userManager.AddToRole(user.Id, "user");
                    if (result.Succeeded)
                    {
                        await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                        // Pour plus d'informations sur l'activation de la confirmation du compte et la réinitialisation du mot de passe, consultez http://go.microsoft.com/fwlink/?LinkID=320771
                        // Envoyer un message électronique avec ce lien
                        // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                        // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                        // await UserManager.SendEmailAsync(user.Id, "Confirmez votre compte", "Confirmez votre compte en cliquant <a href=\"" + callbackUrl + "\">ici</a>");

                        return(RedirectToAction("Index", "Home"));
                    }
                    AddErrors(result);
                }

                // Si nous sommes arrivés là, un échec s’est produit. Réafficher le formulaire
                return(View(model));
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Trace.TraceInformation("Property: {0} Error: {1}",
                                               validationError.PropertyName,
                                               validationError.ErrorMessage);
                    }
                }
                return(View(model));
            }
        }
Ejemplo n.º 6
0
 public ActionResult Souscrire(AbonnementViewModels abo, string nameOfType)
 {
     try
     {
         CarteModels      carteUser  = carte.findCarteByUser(User.Identity.Name);
         AbonnementModels abonnement = new AbonnementModels
         {
             TypeAbonnementModelsID = bdd.TypeAbonnementModels.ToList().Find(t => t.Intitule.Contains(nameOfType)).Id,
             CarteModelsID          = carteUser.Id,
         };
         bdd.AbonnementModels.Add(abonnement);
         //carteUser.AbonnementsModels = carteUser.AbonnementsModels.Add();
         bdd.SaveChanges();
         return(RedirectToAction("Index", "Home"));
     }
     catch
     {
         return(View());
     }
 }
Ejemplo n.º 7
0
 public ActionResult Supprimer(AbonnementViewModels aboviewmodel, string nameOfType)
 {
     try
     {
         CarteModels             carteUser = carte.findCarteByUser(User.Identity.Name);
         List <AbonnementModels> aboList   = carteUser.AbonnementsModels.ToList();
         foreach (AbonnementModels abo in aboList)
         {
             int typeId = abo.TypeAbonnementModelsID;
             TypeAbonnementModels typeAbo = bdd.TypeAbonnementModels.Find(typeId);
             string intitule = typeAbo.Intitule;
             if (intitule.Equals(nameOfType))
             {
                 bdd.AbonnementModels.Remove(abo);
             }
         }
         bdd.SaveChanges();
         return(RedirectToAction("Index", "Home"));
     }
     catch
     {
         return(View());
     }
 }