Exemplo n.º 1
0
        public async Task <IActionResult> EditSelectedLink(int id, string createdBy)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(View("Login"));
            }

            if (!hasPermission(PermissionLevels.EditLinkPermission) && !hasPermission(PermissionLevels.OverrideEditLinkPermission))
            {
                ViewBag.CanNotedit = true;
                return(View("AdminPanel"));
            }

            Models.Link link = await Database.GetLinkById(id);

            if (!LocalDatabase.EditSelectedLink.ContainsKey(User.Identity.Name))
            {
                LocalDatabase.EditSelectedLink.Add(User.Identity.Name, link);
            }
            else
            {
                LocalDatabase.EditSelectedLink[User.Identity.Name] = link;
            }
            return(View("AdminPanel"));
        }
Exemplo n.º 2
0
        public async static Task <Models.Link> GetLinkById(int id)
        {
            using (SqlConnection connection = new SqlConnection(SQL_CONNECTION_STRING))
            {
                await connection.OpenAsync();

                using (SqlCommand command = new SqlCommand(null, connection))
                {
                    command.CommandText = "SELECT * FROM links WHERE id = @id";
                    command.Parameters.AddWithValue("@id", id);
                    //command.Parameters.AddWithValue("@clicked", clicked+1); Should Update
                    using (SqlDataAdapter Adapter = new SqlDataAdapter(command))
                    {
                        DataTable table = new DataTable();

                        Adapter.Fill(table);

                        foreach (DataRow row in table.Rows)
                        { //Vyberame data z Table, vytvarame Objekty a populujeme ich informaciami
                            string createdBy    = row["createdBy"].ToString();
                            string longLink     = row["longLink"].ToString();
                            string shortLink    = row["shortLink"].ToString();
                            int    click        = int.Parse(row["clicked"].ToString());
                            string creationTime = row["creationTime"].ToString();

                            Models.Link linkObj = new Models.Link(id, createdBy, longLink, shortLink, click, creationTime);

                            return(linkObj);
                        }
                    }
                }
                return(null);
            }
        }
Exemplo n.º 3
0
        public ActionResult Edit(string id)
        {
            blog_tb_link model = new blog_tb_link {
                ADD_DATE = DateTime.Now, UPDATE_DATE = DateTime.Now
            };

            if ((!String.IsNullOrEmpty(id)) && id.ToString() != "0")
            {
                model             = Utility.LinkBll.GetEntity(id);
                model.UPDATE_DATE = DateTime.Now;
            }

            Models.Link m = ObjectHelper.CloneProperties <Models.Link>(model);
            return(View("~/Views/" + Utility.Version + "/Link/Edit.cshtml", m));
        }
Exemplo n.º 4
0
        public async static Task <bool> EditLink(Models.Link link, string User, string newOwner)
        {
            using (SqlConnection conn = new SqlConnection(SQL_CONNECTION_STRING))
            { //Možno by bolo dobré implementovať kontrolu toho či sa LoggedInUser = createdBy a ak nie, tak nepovoliť edit?
                string queryString = "UPDATE links";
                queryString += " SET shortLink = @short, longLink = @long, createdBy = @newOwner WHERE id = @id";

                await conn.OpenAsync();

                using (SqlCommand edit = new SqlCommand(queryString, conn))
                {
                    edit.Parameters.AddWithValue("@short", link.shortLink);
                    edit.Parameters.AddWithValue("@long", link.longLink);
                    edit.Parameters.AddWithValue("@newOwner", newOwner);
                    edit.Parameters.AddWithValue("@id", link.id);

                    await edit.ExecuteNonQueryAsync();
                }
            }
            return(true);
        }
Exemplo n.º 5
0
        public async Task <IActionResult> AddLinks(Models.Link newlink)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(View("Login"));
            }

            if (!hasPermission(PermissionLevels.AddLinkPermission))
            {
                ViewBag.CanNotAdd = true;
                return(View("AddLink"));
            }

            if (newlink.shortLink == null || newlink.longLink == null || newlink.shortLink.Count() <= 0 || newlink.longLink.Count() <= 0)
            {
                return(View("AddLink"));
            }

            newlink.createdBy = User.Identity.Name;
            newlink.clicked   = 0;
            ViewBag.Duple     = await Database.GetLinkByShortLink(newlink.shortLink);

            if (newlink.shortLink.ToLower().StartsWith("/") || newlink.shortLink.ToLower().StartsWith("admin") || newlink.shortLink.ToLower().StartsWith("index") || newlink.shortLink.ToLower().StartsWith("404"))
            {
                ViewBag.Error = true;
            }
            else if (ViewBag.Duple == null)
            {
                ViewBag.NewLink = newlink;
                await Database.InsertLink(newlink);

                if (ModelState.IsValid)
                {
                    ModelState.Clear();
                }
            }

            return(View("AddLink"));
        }
Exemplo n.º 6
0
        public async static Task InsertLink(Models.Link link)
        {
            using (SqlConnection conn = new SqlConnection(SQL_CONNECTION_STRING))
            {
                //Toto by malo vložiť long_link a short_link, tieto názvy stĺpcov som používal podľa predošlích funkcii.
                string queryString = "INSERT INTO links (createdBy, shortLink, longLink, clicked)";
                queryString += " VALUES(@createdBy, @shortLink, @longLink, @clicked)";

                await conn.OpenAsync();

                using (SqlCommand insert = new SqlCommand(queryString, conn))
                {
                    insert.Parameters.AddWithValue("@createdBy", link.createdBy);
                    insert.Parameters.AddWithValue("@longLink", link.longLink);
                    insert.Parameters.AddWithValue("@shortLink", link.shortLink);
                    insert.Parameters.AddWithValue("@clicked", link.clicked);

                    await insert.ExecuteNonQueryAsync();

                    await conn.CloseAsync();
                }
            }
        }
Exemplo n.º 7
0
        public async static Task <List <Models.Link> > GetAllLinksByUser(string createdBy)
        {
            List <Models.Link> LinkList = new List <Models.Link>(); //List na vsetky rows

            using (SqlConnection conn = new SqlConnection(SQL_CONNECTION_STRING))
            {
                string queryString = "SELECT * FROM links WHERE createdBy = @createdBy";

                await conn.OpenAsync();

                using (SqlCommand getAll = new SqlCommand(queryString, conn))
                {
                    getAll.Parameters.AddWithValue("@createdBy", createdBy);

                    using (SqlDataAdapter Adapter = new SqlDataAdapter(getAll))
                    {
                        DataTable table = new DataTable();

                        Adapter.Fill(table);

                        foreach (DataRow row in table.Rows)
                        { //Vyberame data z Table, vytvarame Objekty a populujeme ich informaciami
                            int      id           = int.Parse(row["id"].ToString());
                            string   longLink     = row["longLink"].ToString();
                            string   shortLink    = row["shortLink"].ToString();
                            int      click        = int.Parse(row["clicked"].ToString());
                            string[] creationTime = row["creationTime"].ToString().Split(" ");

                            Models.Link linkObj = new Models.Link(id, createdBy, longLink, shortLink, click, creationTime[0]);

                            LinkList.Add(linkObj); //Pridavame do Listu
                        }
                    }
                }
                return(LinkList);
            }
        }