Ejemplo n.º 1
0
        public async Task <IActionResult> Update(int?id, LatestPostDetail events)
        {
            LatestPostDetail viewEvents = _db.LatestPostDetails.Include(c => c.BestDetailesWorkshop).FirstOrDefault(c => c.Id == id && c.IsDeleted == false);

            if (events.Photo != null)
            {
                if (!events.Photo.IsImage())
                {
                    ModelState.AddModelError("", "Event yaratmaq ucun wekil tipi yarat!!!");
                    return(View(viewEvents));
                }
                if (!events.Photo.MaxSize(200))
                {
                    ModelState.AddModelError("", "Wekilin olcusu 200kb-dan az olmalidi!!!");
                    return(View(viewEvents));
                }

                string folder   = Path.Combine("assets", "img", "event");
                string fileName = await events.Photo.SaveImgAsync(_env.WebRootPath, folder);

                viewEvents.Image = fileName;
            }

            viewEvents.IsDeleted = false;
            viewEvents.Title     = events.Title;

            await _db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            LatestPostDetail events = _db.LatestPostDetails
                                      .FirstOrDefault(c => c.IsDeleted == false && c.Id == id);

            if (events == null)
            {
                return(NotFound());
            }
            return(View(events));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create(LatestPostDetail events)
        {
            //if (!ModelState.IsValid) return View();
            bool isExist = _db.LatestPostDetails.Where(c => c.IsDeleted == false)
                           .Any(c => c.Title.ToLower() == events.Title.ToLower());

            if (isExist)
            {
                ModelState.AddModelError("Name", "Bu event artiq movcuddur");
                return(View());
            }
            if (events.Photo == null)
            {
                ModelState.AddModelError("", "Ayeee wekili elave ele!!!");
                return(View());
            }
            if (!events.Photo.IsImage())
            {
                ModelState.AddModelError("", "Event yaratmaq ucun wekil tipi yarat!!!");
                return(View());
            }
            if (!events.Photo.MaxSize(200))
            {
                ModelState.AddModelError("", "Wekilin olcusu 200kb-dan az olmalidi!!!");
                return(View());
            }

            string folder   = Path.Combine("assets", "img", "event");
            string fileName = await events.Photo.SaveImgAsync(_env.WebRootPath, folder);

            events.Image     = fileName;
            events.IsDeleted = false;
            await _db.LatestPostDetails.AddAsync(events);


            List <Subscriber> emails = _db.Subscribers.ToList();

            foreach (Subscriber email in emails)
            {
                SendEmail(email.Email, "Yeni bir event yaradildi.", "<h1>Yeni bir event yaradildi</h1>");
            }

            await _db.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> DeletePost(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            LatestPostDetail events = _db.LatestPostDetails
                                      .FirstOrDefault(c => c.IsDeleted == false && c.Id == id);

            if (events == null)
            {
                return(NotFound());
            }
            events.IsDeleted = true;

            await _db.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }