Ejemplo n.º 1
0
        public IActionResult AddNewEvent(AddEventViewModel addEventViewModel)
        {
            // If all of the validation attributes are valid, create the event and store it
            if (ModelState.IsValid)
            {
                // This is basically a line to convert an EventViewModel to an Event model object
                Event newEvent = new Event {
                    Name         = addEventViewModel.Name,
                    Description  = addEventViewModel.Description,
                    ContactEmail = addEventViewModel.ContactEmail,
                    // Use the category ID selected in the view model to query the DB
                    Category = dbContext.Categories.Find(addEventViewModel.CategoryId)
                };

                // 19.3.2.2 Store (add) a new event to the DB
                dbContext.Events.Add(newEvent);
                dbContext.SaveChanges();

                // Redirects back to the "events" index method above
                return(Redirect("/events"));
            }

            // If there are validation errors, return the same view back with the provided values
            return(View("Add", addEventViewModel));
        }
        public ActionResult CreateCompany(EditModel m)
        {
            EventDbContext db      = new EventDbContext();
            var            company = db.GetCompanies().FirstOrDefault(x => x.EventId == m.SelectedEventId && x.Id == m.Company.Id);

            if (company == null)
            {
                var newCompany = new Company {
                    Name                 = m.Company.Name,
                    RegistryNumber       = m.Company.RegistryNumber,
                    NumberOfParticipants = m.Company.NumberOfParticipants,
                    PaymentMethodId      = m.SelectedPaymentMethodId,
                    Info                 = m.Company.Info,
                    EventId              = m.SelectedEventId,
                    RegisterDate         = DateTime.Now,
                    Active               = true
                };
                db.Companies.Add(newCompany);
                db.SaveChanges();
            }
            else
            {
                var dbCompany = db.Companies.FirstOrDefault(x => x.EventId == m.SelectedEventId && x.Id == m.Company.Id);
                dbCompany.Name                 = m.Company.Name;
                dbCompany.RegistryNumber       = m.Company.RegistryNumber;
                dbCompany.NumberOfParticipants = m.Company.NumberOfParticipants;
                dbCompany.PaymentMethodId      = m.SelectedPaymentMethodId;
                dbCompany.Info                 = m.Company.Info;
                dbCompany.EventId              = m.SelectedEventId;
                UpdateModel(dbCompany);
                db.SaveChanges();
            }
            return(RedirectToAction("Participants", new { id = m.SelectedEventId }));
        }
Ejemplo n.º 3
0
        public IActionResult Add(AddEventViewModel addEventViewModel)
        {
            if (ModelState.IsValid)
            {
                EventCategory theCategory = context.EventCategories.Find(addEventViewModel.CategoryId);
                Event         newEvent    = new Event
                {
                    Name         = addEventViewModel.Name,
                    Location     = addEventViewModel.Location,
                    NumAttendees = addEventViewModel.NumAttendees,
                    Description  = addEventViewModel.Description,
                    //Type = addEventViewModel.Type,
                    Category     = theCategory,
                    ContactEmail = addEventViewModel.ContactEmail
                };

                //EventData.Add(newEvent);
                context.Events.Add(newEvent);
                context.SaveChanges();
                return(Redirect("/Events"));
            }

            List <EventCategory> categories = context.EventCategories.ToList();

            addEventViewModel.Categories = new List <SelectListItem>();
            foreach (var category in categories)
            {
                addEventViewModel.Categories.Add(new SelectListItem
                {
                    Value = category.Id.ToString(),
                    Text  = category.Name
                });
            }
            return(View(addEventViewModel));
        }
        public ActionResult CreatePerson(EditModel m)
        {
            EventDbContext db     = new EventDbContext();
            var            person = db.GetPersons().FirstOrDefault(x => x.EventId == m.SelectedEventId && x.Id == m.Person.Id);

            if (person == null)
            {
                var newPerson = new Person {
                    FirstName       = m.Person.FirstName,
                    LastName        = m.Person.LastName,
                    PersonalCode    = m.Person.PersonalCode,
                    PaymentMethodId = m.SelectedPaymentMethodId,
                    Info            = m.Person.Info,
                    EventId         = m.SelectedEventId,
                    RegisterDate    = DateTime.Now,
                    Active          = true
                };
                db.Persons.Add(newPerson);
                db.SaveChanges();
            }
            else
            {
                var dbPerson = db.Persons.FirstOrDefault(x => x.EventId == m.SelectedEventId && x.Id == m.Person.Id);
                dbPerson.FirstName       = m.Person.FirstName;
                dbPerson.LastName        = m.Person.LastName;
                dbPerson.PersonalCode    = m.Person.PersonalCode;
                dbPerson.PaymentMethodId = m.SelectedPaymentMethodId;
                dbPerson.Info            = m.Person.Info;
                UpdateModel(dbPerson);
                db.SaveChanges();
            }
            return(RedirectToAction("Participants", new { id = m.SelectedEventId }));
        }
        public ActionResult Create([Bind(Include = "Id,CiudadName,CiudadDescription,PostalCode")] Ciudad ciudad)
        {
            if (ModelState.IsValid)
            {
                db.Ciudads.Add(ciudad);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(ciudad));
        }
Ejemplo n.º 6
0
        public IActionResult Add(Tag tag)
        {
            if (ModelState.IsValid)
            {
                context.Tags.Add(tag);
                context.SaveChanges();
                return(Redirect("/Tag/"));
            }

            return(View("Add", tag));
        }
Ejemplo n.º 7
0
        public ActionResult Create([Bind(Include = "Id,Nombre,CodigoPostal")] City city)
        {
            if (ModelState.IsValid)
            {
                db.Citys.Add(city);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(city));
        }
Ejemplo n.º 8
0
        public ActionResult Create(Event @event)
        {
            if (ModelState.IsValid)
            {
                db.Events.Add(@event);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(@event));
        }
Ejemplo n.º 9
0
        public ActionResult Create([Bind(Include = "ID,Nombre,Capacidad,Invitado,Fecha,Negocio")] Event @event)
        {
            if (ModelState.IsValid)
            {
                db.Events.Add(@event);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(@event));
        }
Ejemplo n.º 10
0
        public ActionResult Create([Bind(Include = "Id,CityName,CityDescription,Population,Lada")] City city)
        {
            if (ModelState.IsValid)
            {
                db.Cities.Add(city);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(city));
        }
Ejemplo n.º 11
0
        public ActionResult Create([Bind(Include = "Title,description,StartDate,StartTime,EndDate,EndTime,Location,eventType,OrganizerName,ContactIndo,MaxTickets,AvailableTickets")] Event eventt)
        {
            if (ModelState.IsValid)
            {
                db.Events.Add(eventt);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(eventt));
        }
Ejemplo n.º 12
0
        public ActionResult Create([Bind(Include = "Id,nombreciudad,pais")] City city)
        {
            if (ModelState.IsValid)
            {
                db.Cities.Add(city);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(city));
        }
        public ActionResult Create([Bind(Include = "Id,nombreevento,fechaevento,artistas,comida")] Event @event)
        {
            if (ModelState.IsValid)
            {
                db.Events.Add(@event);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(@event));
        }
        public ActionResult Create([Bind(Include = "Id,NombreEvento,Seguridad,FechaEventoInicio,FechaEventoFinal")] Event @event)
        {
            if (ModelState.IsValid)
            {
                db.Events.Add(@event);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(@event));
        }
        public ActionResult Create([Bind(Include = "Id,Nombre,Descripcion,Fecha,CiudadesId")] Evento evento)
        {
            if (ModelState.IsValid)
            {
                db.Eventoes.Add(evento);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CiudadesId = new SelectList(db.Ciudads, "Id", "CiudadName", evento.CiudadesId);
            return(View(evento));
        }
Ejemplo n.º 16
0
        public ActionResult Create([Bind(Include = "Id,EventName,EventDescription,Fecha,Quota,Availability,CityId")] Event @event)
        {
            if (ModelState.IsValid)
            {
                db.Events.Add(@event);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CityId = new SelectList(db.Cities, "Id", "CityName", @event.CityId);
            return(View(@event));
        }
Ejemplo n.º 17
0
        public ActionResult Create([Bind(Include = "id,Title,Date,Place,CityId")] Evento evento)
        {
            if (ModelState.IsValid)
            {
                db.Eventos.Add(evento);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CityId = new SelectList(db.Cities, "id", "Name", evento.CityId);
            return(View(evento));
        }
        public ActionResult Create([Bind(Include = "Id,Nombre,Description,Fecha,Organisador,CityId")] Event @event)
        {
            if (ModelState.IsValid)
            {
                db.Events.Add(@event);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CityId = new SelectList(db.Citys, "Id", "Nombre", @event.CityId);
            return(View(@event));
        }
Ejemplo n.º 19
0
 public bool AddTicket(Ticket t)
 {
     try
     {
         db.Add(t);
         db.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Ejemplo n.º 20
0
        public void PutEvents(int artistId, int eventId, PutArtistRequest request)
        {
            var artistExists = _context.Artists.Any(x => x.IdArtist.Equals(artistId));
            var eventExists  = _context.Events.Any(x => x.IdEvent.Equals(eventId));

            if (!artistExists || !eventExists)
            {
                throw new ArtistOrEventNotExistingException($"Artist {artistId} or {eventId} doesnt exist");
            }

            var eventToUpdate = _context.Events.Single(x => x.IdEvent.Equals(eventId));

            var eventHasStarted = eventToUpdate.StartDate <= DateTime.Now;

            if (eventHasStarted)
            {
                throw new EventHasStartedException($"The event {eventId} has started");
            }

            var newDateInRange = request.PerfomanceDate >= eventToUpdate.StartDate &&
                                 request.PerfomanceDate <= eventToUpdate.EndDate;

            if (!newDateInRange)
            {
                throw new DateNotInRangeException("The passed date is not in range");
            }

            eventToUpdate.StartDate = request.PerfomanceDate;
            _context.SaveChanges();
        }
Ejemplo n.º 21
0
        public bool Update(int id, UpdateEventDto dto)
        {
            var events = _dbContext
                         .Events
                         .FirstOrDefault(e => e.Id == id);

            if (events is null)
            {
                return(false);
            }
            events.Name        = dto.Name;
            events.Description = dto.Description;
            events.Date        = dto.Date;
            _dbContext.SaveChanges();
            return(true);
        }
Ejemplo n.º 22
0
        public void UpdateArtistPerformanceTime(int idArtist, int idEvent, UpdateArtistPerformanceTimeRequest request)
        {
            var anEvent = _context.Events.Include(e => e.ArtistEvents)
                          .SingleOrDefault(e => e.IdEvent == idEvent);

            if (anEvent == null)
            {
                throw new EventDoesNotExistsException($"Event with an id {idEvent} does not exists");
            }

            var artistEvent = anEvent.ArtistEvents.SingleOrDefault(e => e.IdArtist == idArtist);

            if (artistEvent == null)
            {
                throw new ArtistDoesNotParticipateInAnEventException($"Artist with an id {idArtist} does not participate in an event with an id {idEvent}");
            }

            if (DateTime.Compare(anEvent.StartDate, DateTime.Now) > 0)
            {
                throw new EventAlreadyBegunException("An event has already begun");
            }

            if (!(DateTime.Compare(anEvent.StartDate, request.PerformanceDate) < 0 && DateTime.Compare(request.PerformanceDate, anEvent.EndDate) < 0))
            {
                throw new IncorrectTimeException($"Performance date has to be between {anEvent.StartDate} and {anEvent.EndDate}");
            }

            artistEvent.PerformanceDate = request.PerformanceDate;
            _context.SaveChanges();
        }
Ejemplo n.º 23
0
 public EventData Add(EventData data)
 {
     // data.Id = events.Max(e => e.Id) + 1;
     db.Events.Add(data);
     db.SaveChanges();
     return(data);
 }
Ejemplo n.º 24
0
        public IActionResult AddEvent(AddEventTagViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                int eventId = viewModel.EventId;
                int tagId   = viewModel.TagId;

                List <EventTag> existingItems = context.EventTags
                                                .Where(et => et.EventId == eventId)
                                                .Where(et => et.TagId == tagId)
                                                .ToList();

                if (existingItems.Count == 0)
                {
                    EventTag eventTag = new EventTag
                    {
                        EventId = eventId,
                        TagId   = tagId
                    };
                    context.EventTags.Add(eventTag);
                    context.SaveChanges();
                }

                return(Redirect("/Events/Detail/" + eventId));
            }

            return(View(viewModel));
        }
Ejemplo n.º 25
0
        public IActionResult ModifyPerformanceDate(ModifyPerformanceDateRequest request)
        {
            var artist_event = _context.Artist_Event.SingleOrDefault
                               (
                e => e.IdArtist == request.IdArtist &&
                e.IdEvent == request.IdEvent
                               );

            if (artist_event == null)
            {
                return(NotFound("Brak podanej asocjacji"));
            }

            var ev = _context.Event.Where(e => e.IdEvent == artist_event.IdEvent)
                     .SingleOrDefault();

            if (ev.StartDate.CompareTo(request.PerformanceDate) < 0 || ev.EndDate.CompareTo(request.PerformanceDate) > 0)
            {
                return(BadRequest("Nowa data musi zawierać się w terminie trwania wydarzenia"));
            }

            artist_event.PerfomanceDate = request.PerformanceDate;

            _context.SaveChanges();

            return(Ok());
        }
Ejemplo n.º 26
0
        public static EventDbContext Create()
        {
            var options = new DbContextOptionsBuilder <EventDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            var context = new EventDbContext(options);

            context.Speakers.AddRange(
                new Speaker()
            {
                SpeakerId = 1,
                Name      = "Alexander Wiebe",
                Secret    = "Loves Angular"
            },
                new Speaker()
            {
                SpeakerId = 2,
                Name      = "David Crossman",
                Secret    = "Loves Git"
            },
                new Speaker()
            {
                SpeakerId = 3,
                Name      = "Patrick Ullrich",
                Secret    = "Loves .NET Core"
            }
                );

            context.Sessions.AddRange(
                new Domain.Entities.Session()
            {
                SessionId   = 1,
                Title       = "Angular State Management: Beyond NGRX",
                Description = "NGRX is a large opinionated library on how to do state management in Angular and is often marketed as ‘The Solution’ to all your state management woes. This talk is to tell you that NGRX isn’t the panacea to every ailment. On top of not curing my baldness NGRX is not always how to solve state management. There’s lots of other ways to deal with state management in Angular. This talk walks through the life of an Angular app and the appropriate state management tactics at different milestones. One size does not fit all. Of course, an internet bucket of hype has to be based on something, so we’ll finish with ‘when you need NGRX how to get started.",
                SignUps     = 0,
                SpeakerId   = 1
            },
                new Domain.Entities.Session()
            {
                SessionId   = 2,
                Title       = "Demystifying Git - Git Under the Hood",
                Description = "When working within a project using Git, you notice a folder .git with a bunch of files and folders containing all types of information. The technical talk will cover some plumbing and porcelain commands with Git and how it manages your files within the .git folder. We will do a deep dive into how Git store data and how it all comes together to track changes for files and folders.",
                SignUps     = 0,
                SpeakerId   = 2
            },
                new Domain.Entities.Session()
            {
                SessionId   = 3,
                Title       = "Vertical Slice Architecture with .Net Core and MediatR - A Work in Progress",
                Description = "A good architecture should reduce business risk associated to the solution. This is a hard task, especially if requirements can change constantly. Inspired by Jimmy Bogards talk on Vertical Slice Architecture, we will build out a foundation for a project using Dot Net Core 2.2 and MediatR and walk through some real life scenarios to see if the architecture can adapt to any new requirements we are introducing.",
                SignUps     = 0,
                SpeakerId   = 3
            }
                );

            context.SaveChanges();

            return(context);
        }
Ejemplo n.º 27
0
        public bool Update(int id, UpdatePersonDto dto)
        {
            var people = _dbContext
                         .People
                         .FirstOrDefault(e => e.Id == id);

            if (people is null)
            {
                return(false);
            }
            people.Name      = dto.Name;
            people.Surname   = dto.Surname;
            people.Email     = dto.Email;
            people.BirthDate = dto.BirthDate;
            _dbContext.SaveChanges();
            return(true);
        }
Ejemplo n.º 28
0
        public static void Proceed(EventDbContext dbContext, UserManager <User> userManager, RoleManager <IdentityRole> roleManager)
        {
            //dbContext.Database.EnsureDeleted();

            dbContext.Database.EnsureCreated();

            if (!roleManager.RoleExistsAsync(AppRoles.userRole).Result)
            {
                roleManager.CreateAsync(new IdentityRole(AppRoles.userRole)).Wait();
            }

            if (!roleManager.RoleExistsAsync(AppRoles.organaizerRole).Result)
            {
                roleManager.CreateAsync(new IdentityRole(AppRoles.organaizerRole)).Wait();
            }

            if (!roleManager.RoleExistsAsync(AppRoles.adminRole).Result)
            {
                roleManager.CreateAsync(new IdentityRole(AppRoles.adminRole)).Wait();
            }

            User      user = dbContext.Users.FirstOrDefault(x => x.UserName.Equals("Dmytro"));
            Organizer organizer;

            if (user is null)
            {
                user = new User {
                    UserName = "******", LastName = "Laskuryk", Email = "*****@*****.**", SecurityStamp = Guid.NewGuid().ToString()
                };

                userManager.CreateAsync(user, "111111").Wait();

                userManager.AddToRoleAsync(user, AppRoles.organaizerRole).Wait();
                userManager.AddToRoleAsync(user, AppRoles.userRole).Wait();
                userManager.AddToRoleAsync(user, AppRoles.adminRole).Wait();
            }

            organizer = dbContext.Organizers.FirstOrDefault(x => x.OrganizerId.Equals(user.Id));

            if (organizer is null)
            {
                organizer = new Organizer {
                    InstType = "some_info", PlaceName = "Cafe", TelNumber = "11111", Position = "Boss", User = user
                };

                dbContext.Organizers.Add(organizer);
                dbContext.SaveChanges();
            }

            if (!dbContext.Events.Any(x => x.OrganizerId == organizer.OrganizerId))
            {
                var list = new List <Event>
                {
                    new Event {
                        Name = "Event_1", Description = "Description_1", Address = "Address_1", StartTime = DateTime.Now.AddDays(5), StartDate = DateTime.Now.AddDays(5), Price = 1_000, Quantity = 100, OrganizerId = organizer.OrganizerId
                    },
        public ActionResult DeactivatePerson(int id, int eventId)
        {
            EventDbContext db       = new EventDbContext();
            var            dbPerson = db.Persons.FirstOrDefault(x => x.Id == id && x.EventId == eventId);

            dbPerson.Active = false;
            UpdateModel(dbPerson);
            db.SaveChanges();
            return(RedirectToAction("Participants", new { id = eventId }));
        }
        public ActionResult DeactivateEvent(int id)
        {
            EventDbContext db      = new EventDbContext();
            var            dbEvent = db.Events.FirstOrDefault(x => x.Id == id);

            dbEvent.Active = false;
            UpdateModel(dbEvent);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }