public string DeleteCategory(int id)
        {
            try
            {
                BlogForPrContext db = new BlogForPrContext();
                var tempCat         = db.Categories.Find(id);
                db.Categories.Remove(tempCat);
                int result = db.SaveChanges();

                return(result == 1 ? "Deleted succesfuly!" : "Delete Failed!");
            }
            catch (Exception ex)
            {
                string msg = "A problem caused during deleting category. Exception message : " + ex.Message;
                return(msg);
            }
        }
        public string AddCategory(Categories entity)
        {
            try
            {
                BlogForPrContext db = new BlogForPrContext();

                db.Categories.Add(entity);
                var result = db.SaveChanges();

                return(result == 1 ? "Added succesfuly!" : "Adding Failed!");
            }
            catch (Exception ex)
            {
                string msg = "A problem caused during adding category. Exception message : " + ex.Message;
                return(msg);
            }
        }
Example #3
0
        public string AddPost(Posts entity)
        {
            try
            {
                BlogForPrContext db = new BlogForPrContext();
                entity.DatetimeOfCreated = DateTime.Now;

                db.Posts.Add(entity);
                int result = db.SaveChanges();

                return(result == 1 ? "Added succesfuly!" : "Adding Failed!");
            }
            catch (Exception ex)
            {
                string msg = "A problem caused during adding post. Exception message : " + ex.Message;
                return(msg);
            }
        }
        public string UpdateCategory(Categories entity)
        {
            try
            {
                BlogForPrContext db = new BlogForPrContext();

                var tempCat = db.Categories.Find(entity.Id);
                tempCat.CategoryName = entity.CategoryName;

                int result = db.SaveChanges();

                return(result == 1 ? "Updated succesfuly!" : "Update Failed!");
            }
            catch (Exception ex)
            {
                string msg = "A problem caused during updating category. Exception message : " + ex.Message;
                return(msg);
            }
        }
        public string ChangePassword(Admin entity)
        {
            try
            {
                BlogForPrContext db        = new BlogForPrContext();
                Admin            tempAdmin = db.Admin.FirstOrDefault();

                int result = 0;


                tempAdmin.Password = entity.Password;
                result             = db.SaveChanges();


                return(result == 1 ? "Password updated!" : "Error");
            }
            catch (Exception ex)
            {
                string msg = "A problem caused during changing password as admin. Exception message : " + ex.Message;
                return(msg);
            }
        }
Example #6
0
        public string UpdatePost(Posts entity)
        {
            try
            {
                BlogForPrContext db = new BlogForPrContext();

                var tempPost = db.Posts.Find(entity.Id);

                tempPost.Title      = entity.Title;
                tempPost.Info       = entity.Info;
                tempPost.Text       = entity.Text;
                tempPost.CategoryId = entity.CategoryId;
                int result = db.SaveChanges();

                return(result == 1 ? "Updated succesfuly!" : "Update Failed!");
            }
            catch (Exception ex)
            {
                string msg = "A problem caused during updating post. Exception message : " + ex.Message;
                return(msg);
            }
        }