Ejemplo n.º 1
0
        public static void StartSeed(EventsDbContext context)
        {
            //context.Attender.RemoveRange(context.Attender);
            //context.Event.RemoveRange(context.Event);

            Attender Lolo = new Attender {
                name = "Lolo", email = "*****@*****.**", phone_number = "0731337123"
            };

            context.Attender.Add(Lolo);

            context.Event.AddRange(new List <Event>()
            {
                new Event()
                {
                    title = "Bollspel", date = DateTime.Now, adress = "Norrköping", spots_available = 400
                },
                new Event()
                {
                    title = "Coronafest", date = DateTime.Now, adress = "Kungsbacka", spots_available = 400
                },
                new Event()
                {
                    title = "Fotboll", date = DateTime.Now, adress = "Göteborg", spots_available = 400
                },
                new Event()
                {
                    title = "Vintest", date = DateTime.Now, adress = "Mölndal", spots_available = 400
                },
            });

            context.SaveChanges();
        }
Ejemplo n.º 2
0
        public ActionResult Create(string Name, int?Age, string Comments, string Profesion, bool ReturnNextYear, int[] TalksIds)
        {
            try
            {
                var attender = new Attender();

                if (string.IsNullOrEmpty(Name))
                {
                    ModelState.AddModelError("Name", "El nombre es un campo obligatorio.");
                }
                else
                {
                    attender.Name = Name;
                }


                if (!Age.HasValue || Age.Value == 0)
                {
                    ModelState.AddModelError("Age", "La edad es un campo obligatorio.");
                }
                else
                {
                    attender.Age = Age.Value;
                }

                attender.Comments       = Comments;
                attender.Profesion      = Profesion;
                attender.ReturnNextYear = ReturnNextYear;
                attender.TalksIds       = TalksIds;

                if (!ModelState.IsValid)
                {
                    ViewData["TalksList"] = GetTalksList(attender.TalksIds);
                    return(View());
                }

                AttenderRepository.AddAttender(attender);

                return(RedirectToAction("Index"));
            }
            catch
            {
                ViewData["TalksList"] = GetTalksList();

                return(View());
            }
        }
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            Attender = await _context.Attender
                       .Where(a => a.Id == 1)
                       .FirstOrDefaultAsync();

            Event = await _context.Event.FirstOrDefaultAsync(m => m.Id == id);



            if (Event == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Ejemplo n.º 4
0
        public ActionResult Edit(Attender attender)
        {
            try
            {
                if (string.IsNullOrEmpty(attender.Name))
                {
                    ModelState.AddModelError("Name", "El nombre es un campo obligatorio.");
                }

                if (attender.Age == 0)
                {
                    ModelState.AddModelError("Age", "La edad es un campo obligatorio.");
                }

                if (!ModelState.IsValid)
                {
                    ViewData["TalksList"] = GetTalksList(attender.TalksIds);

                    return(View());
                }

                var currentAttender = AttenderRepository.GetAttender(attender.Id);

                currentAttender.Name           = attender.Name;
                currentAttender.Age            = attender.Age;
                currentAttender.Comments       = attender.Comments;
                currentAttender.ReturnNextYear = attender.ReturnNextYear;
                currentAttender.TalksIds       = attender.TalksIds;

                return(RedirectToAction("Index"));
            }
            catch
            {
                ViewData["TalksList"] = GetTalksList(attender.TalksIds);

                return(View());
            }
        }