Пример #1
0
        public IActionResult Detail(int?id)
        {
            UpComingEvent UpComingEvent = _db.UpComingEvents.Include(c => c.SpeakerEvents).ThenInclude(p => p.Speaker).FirstOrDefault(p => p.Id == id);



            return(View(UpComingEvent));
        }
Пример #2
0
        public IActionResult Detail(int?id)
        {
            if (id == null)
            {
                return(View());
            }
            UpComingEvent upComingEvent = _db.UpComingEvents.Include(c => c.Category).Include(c => c.SpeakerEvents).ThenInclude(c => c.Speaker).FirstOrDefault(p => p.Id == id);

            return(View(upComingEvent));
        }
Пример #3
0
        public IActionResult Update(int?id)
        {
            ViewBag.Category = new SelectList(_db.Categories.ToList(), "Id", "Name");
            ViewBag.Speaker  = _db.Speakers.ToList();
            if (id == null)
            {
                return(View());
            }
            UpComingEvent upComingEvent = _db.UpComingEvents.Include(c => c.SpeakerEvents).ThenInclude(c => c.Speaker).FirstOrDefault(p => p.Id == id);

            // var vm = _mapper.Map<UpComingEvent,UpComingGetVm>(upComingEvent);
            return(View(upComingEvent));
        }
Пример #4
0
        public IActionResult Delete(int?id)
        {
            ViewBag.Speaker = _db.Speakers.ToList();
            if (id == null)
            {
                return(View());
            }
            UpComingEvent upComingEvent = _db.UpComingEvents.Include(c => c.SpeakerEvents).ThenInclude(c => c.Speaker).FirstOrDefault(p => p.Id == id);

            if (upComingEvent == null)
            {
                return(View());
            }
            return(View(upComingEvent));
        }
Пример #5
0
        public IActionResult DeleteEvent(int?id)
        {
            ViewBag.Speaker = _db.Speakers.ToList();
            if (id == null)
            {
                return(View());
            }
            UpComingEvent upComingEvent = _db.UpComingEvents.Include(c => c.SpeakerEvents).ThenInclude(c => c.Speaker).FirstOrDefault(p => p.Id == id);

            if (upComingEvent == null)
            {
                return(View());
            }
            _db.UpComingEvents.Remove(upComingEvent);

            foreach (var item in upComingEvent.SpeakerEvents)
            {
                _db.SpeakerEvents.Remove(item);
            }
            _db.SaveChanges();
            return(RedirectToAction(nameof(Index)));
        }
Пример #6
0
        public async Task <IActionResult> Create([FromForm] UpComingEventCreateVM upComingEventCreateVM)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!upComingEventCreateVM.Photo.IsImage())
            {
                ModelState.AddModelError("Photo", "Zehmet olmasa shekil formati sechin");
                return(BadRequest(ModelState));
            }

            if (upComingEventCreateVM.Photo.MaxLength(2000))
            {
                ModelState.AddModelError("Photo", "Shekilin olchusu max 200kb ola biler");
                return(BadRequest(ModelState));
            }
            if (upComingEventCreateVM.SpeakerEventsId == null)
            {
                ModelState.AddModelError("", "Speaker Secmelisiniz!");
                return(BadRequest(ModelState));
            }
            string        path          = Path.Combine("img", "event");
            UpComingEvent upComingEvent = new UpComingEvent
            {
                Title       = upComingEventCreateVM.Title,
                Image       = await upComingEventCreateVM.Photo.SaveImg(_env.WebRootPath, path),
                Month       = upComingEventCreateVM.Month,
                Day         = upComingEventCreateVM.Day,
                Location    = upComingEventCreateVM.Location,
                StartTime   = upComingEventCreateVM.StartTime,
                EndTime     = upComingEventCreateVM.EndTime,
                Description = upComingEventCreateVM.Description,
                CategoryId  = upComingEventCreateVM.CategoryId
            };



            await _db.UpComingEvents.AddAsync(upComingEvent);

            await _db.SaveChangesAsync();

            foreach (var speakerId in upComingEventCreateVM.SpeakerEventsId)
            {
                var speaker = _db.Speakers.Include(p => p.SpeakerEvents).ThenInclude(p => p.UpComingEvent).FirstOrDefault(p => p.Id == speakerId);
                foreach (var se in speaker.SpeakerEvents)
                {
                    if (upComingEvent.StartTime > se.UpComingEvent.StartTime && upComingEvent.EndTime < se.UpComingEvent.EndTime)
                    {
                        ModelState.AddModelError("", "Busy");
                        return(BadRequest(ModelState));
                    }
                }
                SpeakerEvent speakerEvent = new SpeakerEvent
                {
                    SpeakerId       = speakerId,
                    UpComingEventId = upComingEvent.Id
                };
                _db.SpeakerEvents.Add(speakerEvent);

                await _db.SaveChangesAsync();
            }
            var callbackUrl = Url.Action(
                "Detail",
                "Event",
                new { Id = upComingEventCreateVM.Id },
                protocol: HttpContext.Request.Scheme);
            EmailService  email = new EmailService();
            List <string> e     = _db.Subscriptions.Select(x => x.Email).ToList();
            await email.SendEmailAsync(e, "Yeni event",
                                       "Yeni event: <a href=https://localhost:44375/Event/Detail/" + $"{upComingEvent.Id}" + ">link</a>");


            return(Ok($"{upComingEvent.Id} li element yaradildi"));
        }