Ejemplo n.º 1
0
        public IActionResult EditPost([FromForm] Blog BlogEdit, IFormFile file)
        {
            try
            {
                var namePicture = string.Empty;
                var roleId      = HttpContext.Items["RoleID"];
                var roldIdInt   = int.Parse(roleId.ToString());
                if (roleId == null || roldIdInt != 1)
                {
                    return(Json(new { status = 403, message = "Forbidden" }));
                }

                if (file != null)
                {
                    namePicture = _blogService.SaveImageToAssertAndReturnFileName(file);
                }
                bool isUpdateComplete = _blogService.UpdateBlog(BlogEdit, namePicture);
                if (isUpdateComplete)
                {
                    return(Json(new { status = 200, message = "Update complete" }));
                }
                return(Json(new { status = 500, message = "Update failed" }));
            }
            catch (Exception e)
            {
                return(Json(new { status = 500, message = "Update failed" + e }));
            }
        }
Ejemplo n.º 2
0
        public IActionResult Edit([FromForm] Blog BlogEdit, IFormFile file)
        {
            using (var transaction = new TransactionScope())
            {
                try
                {
                    var namePicture = string.Empty;
                    var UserID      = int.Parse(HttpContext.Items["UserID"].ToString());
                    var userIdBlog  = BlogEdit.Author.UserID;
                    if (UserID != userIdBlog)
                    {
                        return(Json(new { status = 403, message = "Forhibben" }));
                    }
                    if (file != null)
                    {
                        namePicture = _blogService.SaveImageToAssertAndReturnFileName(file);
                    }

                    bool isUpdateComplete = _blogService.UpdateBlog(BlogEdit, namePicture);

                    transaction.Complete();

                    if (isUpdateComplete)
                    {
                        return(Json(new { status = 200, message = "Update complete" }));
                    }
                    return(Json(new { status = 500, message = "Update failed" }));
                }
                catch (Exception e)
                {
                    return(Json(new { status = 500, message = "Update failed" + e }));
                }
            }
        }
        public void UpdateBlog()
        {
            NinjectCommon.Ninject.Registration();
            blogLogic = NinjectCommon.Ninject.Kernel.Get <IBlogLogic>();
            var result = blogLogic.UpdateBlog("2", "5");

            Assert.IsTrue(result, "False");
        }
Ejemplo n.º 4
0
 public bool UpdateBlog(Blog blog, string fileName)
 {
     return(_blogservice.UpdateBlog(blog, fileName));
 }
Ejemplo n.º 5
0
        private static void ModeratorMethod(User user)
        {
            while (true)
            {
                Console.WriteLine("MODERATOR");
                Console.WriteLine("You can: ");
                Console.WriteLine("Update yourself - 1");
                Console.WriteLine("Create blog - 2");
                Console.WriteLine("Update blog - 3");
                Console.WriteLine("See information about you - 4");
                Console.WriteLine("Update blog how admin - 5");
                Console.WriteLine("See your blogs - 6");
                Console.WriteLine("If you wanna exit press Esc");

                var action = Console.ReadKey();

                switch (action.Key)
                {
                case ConsoleKey.Escape:
                    return;

                case ConsoleKey.D1:
                    Console.Write("New Name: ");
                    var userName_1 = Console.ReadLine();
                    Console.Write("New Password: "******"Update ready!");
                    }
                    else
                    {
                        Console.WriteLine("Can't update");
                    }
                    break;

                case ConsoleKey.D2:
                    Console.Write("Blog's Name: ");
                    var blogName_2 = Console.ReadLine();
                    Console.Write("Blog's Text: ");
                    var blogText_2 = Console.ReadLine();
                    if (blogLogic.CreateBlog(user.UserId.ToString(), blogName_2, blogText_2))
                    {
                        Console.WriteLine("Create Blog!");
                    }
                    else
                    {
                        Console.WriteLine("Can't create blog");
                    }
                    break;

                case ConsoleKey.D3:
                    Console.Write("Blog's ID: ");
                    var blogId_3 = Console.ReadLine();
                    Console.Write("Blog's Rating: ");
                    var blogRating_3 = Console.ReadLine();
                    if (blogLogic.UpdateBlog(blogId_3, blogRating_3))
                    {
                        Console.WriteLine("Update ready!");
                    }
                    else
                    {
                        Console.WriteLine("Can't update");
                    }
                    break;

                case ConsoleKey.D4:
                    Console.WriteLine($"ID : {user.UserId}{Environment.NewLine}Name : {user.Name}{Environment.NewLine}Password : {user.Password}{Environment.NewLine}Role : {user.Role}{Environment.NewLine}");
                    break;

                case ConsoleKey.D5:
                    Console.Write("Blog's ID: ");
                    var blogId_5 = Console.ReadLine();
                    Console.Write("Name: ");
                    var blogName_5 = Console.ReadLine();
                    Console.Write("Text: ");
                    var blogText_5 = Console.ReadLine();
                    Console.Write("Rating : ");
                    var blogRating_5 = Console.ReadLine();
                    if (blogLogic.UpdateBlogByAdmin(blogId_5, blogName_5, blogText_5, blogRating_5))
                    {
                        Console.WriteLine("Update ready!");
                    }
                    else
                    {
                        Console.WriteLine("Can't update");
                    }
                    break;

                case ConsoleKey.D6:
                    var result_5 = blogLogic.GetBlogsByUser(user.UserId.ToString());
                    if (result_5 != null)
                    {
                        foreach (var item in result_5)
                        {
                            Console.WriteLine($"ID : {item.BlogId}{Environment.NewLine}Name : {item.Name}{Environment.NewLine}Rating : {item.Rating}{Environment.NewLine}Text : {Environment.NewLine}{item.Text}{Environment.NewLine}");
                        }
                    }
                    else
                    {
                        Console.WriteLine("You haven't blogs");
                    }
                    break;

                default:
                    break;
                }
            }
        }