Ejemplo n.º 1
0
        public IActionResult Add(AuthorVM model, int[] categoryid)
        {
            if (ModelState.IsValid)
            {
                Author author = new Author();
                author.ID        = model.ID;
                author.Name      = model.Name;
                author.SurName   = model.Surname;
                author.EMail     = model.EMail;
                author.Phone     = model.Phone;
                author.BirthDate = model.BirthDate;

                _newscontext.Authors.Add(author);
                _newscontext.SaveChanges();

                int authorid = author.ID;

                model.Categories = _newscontext.Categories.ToList();

                for (int i = 0; i < categoryid.Length; i++)
                {
                    AuthorCategory authorcategory = new AuthorCategory();
                    authorcategory.CategoryID = categoryid[i];
                    authorcategory.AuthorID   = authorid;
                    _newscontext.AuthorCategories.Add(authorcategory);
                }
                _newscontext.SaveChanges();
            }
            else
            {
                return(View(GetAuthorForAdd()));
            }

            return(Redirect("/Admin/Author/Index/"));
        }
Ejemplo n.º 2
0
 public IActionResult Add(CategoryVM model, int?uppercategoryid)
 {
     if (ModelState.IsValid)
     {
         if (uppercategoryid == 1)
         {
             Category category = new Category();
             category.CategoryName    = model.Name;
             category.Description     = model.Description;
             category.UpperCategoryID = 1;
             _newscontext.Categories.Add(category);
             _newscontext.SaveChanges();
         }
         else
         {
             Category subcategory = new Category();
             subcategory.UpperCategoryID = uppercategoryid;
             subcategory.CategoryName    = model.Name;
             subcategory.Description     = model.Description;
             _newscontext.Categories.Add(subcategory);
             _newscontext.SaveChanges();
         }
     }
     else
     {
         return(View(GetCategoryVMForAdd()));
     }
     return(Redirect("/Admin/Category/Index"));
 }
        public IActionResult AddComment(NewsVM model)
        {
            Comment comment = new Comment();
            User    user    = new User();
            News    news    = _newscontext.News.FirstOrDefault(x => x.ID == model.ID);

            model.Title = news.Title;

            comment.NewsId   = model.ID;
            comment.Content  = model.Comment.Content;
            user             = _newscontext.Users.Where(q => q.EMail == model.UserEmail).FirstOrDefault();
            comment.UserId   = user.ID;
            comment.ParentId = 0;

            _newscontext.Comments.Add(comment);
            _newscontext.SaveChanges();
            string url = "/haber/" + model.ID + "/" + UrlHelpers.FriendlyUrl(model.Title);

            return(Redirect(url));
        }
Ejemplo n.º 4
0
        public IActionResult Add(UserVM model)
        {
            if (ModelState.IsValid)
            {
                User user = new User();
                user.Name      = model.Name;
                user.SurName   = model.SurName;
                user.EMail     = model.EMail;
                user.NickName  = model.NickName;
                user.Password  = model.Password;
                user.BirthDate = model.BirthDate;

                _newscontext.Users.Add(user);
                _newscontext.SaveChanges();
            }
            else
            {
                return(View());
            }

            return(Redirect("/Admin/User/Index/"));
        }
Ejemplo n.º 5
0
        public IActionResult Edit(CommentVM model, int userid, int newsid)
        {
            Comment comments = _newscontext.Comments.FirstOrDefault(q => q.ID == model.ID);

            if (ModelState.IsValid)
            {
                comments.Content = model.Content;
                comments.NewsId  = newsid;
                comments.UserId  = userid;
            }
            else
            {
                model.ID      = comments.ID;
                model.News    = _newscontext.News.ToList();
                model.Users   = _newscontext.Users.ToList();
                model.Content = comments.Content;

                return(View(model));
            }

            _newscontext.SaveChanges();
            return(Redirect("/Admin/Comment/Index/"));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Login(MainLoginVM model)
        {
            if (ModelState.IsValid)
            {
                User user = _newscontext.Users.FirstOrDefault(x => x.EMail == model.EMail && x.Password == model.Password && x.IsActive == true && x.IsDeleted == false);
                if (user != null)
                {
                    var claims = new List <Claim>
                    {
                        new Claim(ClaimTypes.Email, model.EMail),
                        new Claim(ClaimTypes.Name, user.Name),
                        new Claim(ClaimTypes.UserData, "Site")
                    };

                    var userIdentity = new ClaimsIdentity(claims, "login");

                    ClaimsPrincipal principal = new ClaimsPrincipal(userIdentity);

                    await HttpContext.SignInAsync("UserScheme", principal);

                    user.LastLogin = DateTime.Now;

                    _newscontext.SaveChanges();

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ViewBag.error = "Email veya şifre hatalı";
                    return(View());
                }
            }
            else
            {
                return(View());
            }
        }
        public async Task <IActionResult> Index(LoginVM model)
        {
            if (ModelState.IsValid)
            {
                AdminUser adminuser = _newscontext.AdminUsers.FirstOrDefault(x => x.EMail == model.EMail && x.Password == model.Password);
                if (adminuser != null)
                {
                    var claims = new List <Claim>
                    {
                        new Claim(ClaimTypes.Name, model.EMail),
                        new Claim(ClaimTypes.Role, adminuser.Role),
                        new Claim(ClaimTypes.UserData, "Admin")
                    };

                    var userIdentity = new ClaimsIdentity(claims, "login");

                    ClaimsPrincipal principal = new ClaimsPrincipal(userIdentity);

                    await HttpContext.SignInAsync("AdminScheme", principal);

                    adminuser.LastLoginDate = DateTime.Now;

                    _newscontext.SaveChanges();

                    return(Redirect("/Admin/Home/Index/"));
                }
                else
                {
                    ViewBag.error = "Email veya şifre hatalı!";
                    return(View());
                }
            }
            else
            {
                return(View());
            }
        }
Ejemplo n.º 8
0
        public IActionResult Add(NewsVM model, int authorid, int categoryid)
        {
            List <string> paths = new List <string>();


            string imgpath = "";

            if (model.articleimages != null)
            {
                foreach (var item in model.articleimages)
                {
                    //adminin eklediği resim 5 mb dan büyük ise ekranda uyarı versin . MB kontrolü backend den yani bu kod bloğundan yapılacak
                    var guid = Guid.NewGuid().ToString();

                    var path = Path.Combine(
                        Directory.GetCurrentDirectory(),
                        "wwwroot/adminsite/assets/articleimg", guid + ".jpg");
                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        item.CopyTo(stream);
                    }

                    imgpath = guid + ".jpg";
                    paths.Add(imgpath);
                }
            }

            model.MainImagePath = paths;


            if (ModelState.IsValid)
            {
                News article = new News();
                article.Title      = model.Title;
                article.SubTitle   = model.SubTitle;
                article.Content    = model.Content;
                article.AuthorID   = authorid;
                article.CategoryID = categoryid;

                _newscontext.News.Add(article);
                _newscontext.SaveChanges();

                int newsid = article.ID;

                foreach (var item in model.MainImagePath)
                {
                    Pictures image = new Pictures();
                    image.ImagePath = item;
                    image.NewsId    = newsid;

                    _newscontext.Pictures.Add(image);
                }

                _newscontext.SaveChanges();
            }
            else
            {
                return(View(GetNewsVMForAdd()));
            }


            return(Redirect("/Admin/News/Index/"));
        }
        public IActionResult Register(MainRegisterVM model)
        {
            if (ModelState.IsValid)
            {
                User existingUser = _newscontext.Users.FirstOrDefault(x => x.EMail == model.EMail);

                if (existingUser == null)
                {
                    string confirmcode = Guid.NewGuid().ToString();
                    User   user        = new User();
                    user.Name        = model.Name;
                    user.SurName     = model.Surname;
                    user.NickName    = model.Username;
                    user.BirthDate   = model.BirthDate;
                    user.EMail       = model.EMail;
                    user.Password    = model.Password;
                    user.ConfirmCode = confirmcode;
                    user.IsActive    = false;

                    _newscontext.Users.Add(user);
                    _newscontext.SaveChanges();

                    //email gönderme kodu. EMail ile kullanıcıya 31. satırdaki confirmcode u yolla.
                    //http://localhost:5000/Register/Confirm/22336525112asd

                    string confirmurl = "http://sportsnewsprojectapp.herokuapp.com./Register/Confirm/" + confirmcode;

                    MimeMessage message = new MimeMessage();

                    MailboxAddress from = new MailboxAddress("SportsNewsTeam", "*****@*****.**");
                    message.From.Add(from);

                    MailboxAddress to = new MailboxAddress(user.Name, user.EMail);
                    message.To.Add(to);

                    message.Subject = "no-reply";

                    BodyBuilder bodyBuilder = new BodyBuilder();
                    bodyBuilder.TextBody = "Please click on the link to confirm your email address: " + confirmurl;

                    message.Body = bodyBuilder.ToMessageBody();

                    SmtpClient client = new SmtpClient();

                    client.Connect("smtp.gmail.com", 465, true);
                    client.Authenticate("*****@*****.**", "$Rdot3PxrtV9QQpYFzVYA#w%RpU2!BGC5UN8cSXNhAs@iq@GvZ");


                    client.Send(message);
                    client.Disconnect(true);
                    client.Dispose();

                    return(RedirectToAction("PendingPage", "Register"));
                }
                else
                {
                    ModelState.AddModelError("EMail", "Bu email adresini kullanan bir hesap var, lütfen farklı bir email adresi girin! Ya da hesabınız varsa giriş yapmayı deneyin...");
                    return(View());
                }
            }
            else
            {
                return(View());
            }
        }