public bool EditUserName(int id, string newname)
        {
            Model1 testcontext = new Model1();
            users  tmp         = new users();

            try
            {
                tmp = testcontext.users.First(i => i.id == id);
                UserInfo newuser = new UserInfo(tmp.id, newname, tmp.passsword);
                DeleteUser(id);
                newuser.AddUser();
                testcontext.SaveChanges();
            }
            catch
            {
                return(false);
            }
            return(true);
        }
Esempio n. 2
0
        public string EditText(string Title = null, string Lead = null, string Content = null, int CategoryId = -1, List <int> Tags = null)
        {
            string ret = "Edytowano tekst";

            try
            {
                using (var db = new Model1())
                {
                    var temp = db.Art.SingleOrDefault(b => b.Title == Title && b.CategoryId == CategoryId);
                    if (temp != null)
                    {
                        if (Title != null)
                        {
                            temp.Title = Title;
                        }
                        if (Lead != null)
                        {
                            temp.Lead = Lead;
                        }
                        if (Content != null)
                        {
                            temp.Content = Content;
                        }
                        if (CategoryId != -1)
                        {
                            temp.CategoryId = CategoryId;
                        }
                        if (Tags != null)
                        {
                            temp.Tags = Tags.ToString();
                        }
                    }
                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                ret = "Ponów akcję: " + e;
            }

            return(ret);
        }
        public bool DeleteUser(int id)
        {
            Model1 testcontext = new Model1();
            users  tmp         = testcontext.users.First(i => i.id == id);

            if (tmp == null)
            {
                return(true);
            }
            try
            {
                testcontext.users.Remove(tmp);
                testcontext.SaveChanges();
            }
            catch
            {
                return(false);
            }
            return(true);
        }
Esempio n. 4
0
        public string DeleteText(string Title, int CategoryId)
        {
            string ret = "Usunięto tekst";

            try
            {
                using (var db = new Model1())
                {
                    var result = db.Art.SingleOrDefault(b => b.Title == Title && b.CategoryId == CategoryId);
                    if (result != null)
                    {
                        db.Art.Remove(result);
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception e)
            {
                ret = "Ponów akcję: " + e;
            }

            return(ret);
        }
Esempio n. 5
0
        public string PublishText(string Title, int CategoryId)
        {
            string ret = "Wysłano tekst";

            try
            {
                using (var db = new Model1())
                {
                    var result = db.Art.SingleOrDefault(b => b.Title == Title && b.CategoryId == CategoryId);
                    if (result != null)
                    {
                        result.IsPublish = 1;
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception e)
            {
                ret = "Ponów akcję: " + e;
            }

            return(ret);
        }
        public bool AddUser()
        {
            Model1 testcontext = new Model1();
            users  tmp         = new users();

            tmp.id        = this.id;
            tmp.name      = this.name;
            tmp.passsword = this.pass;
            if (TestOnDB(tmp) == true)
            {
                return(false);
            }
            try
            {
                testcontext.users.Add(tmp);
                testcontext.SaveChanges();
            }
            catch
            {
                return(false);
            }
            return(true);
        }