Ejemplo n.º 1
0
        public IActionResult OnGet(int id)
        {
            if (!_context.Posts.Any(p => p.Id == id))
            {
                return(RedirectToPage("Index"));
            }
            PopulateOptions();
            Post = _context.Posts.Where(p => p.Id == id).Include(p => p.Content).ThenInclude(c => c.Language).FirstOrDefault();
            var Contents = Post.Content ?? new List <Content>();

            //Check if content list has all languages
            if (Contents.Count != Languages.Count)
            {
                //Populate Content with amount of language options, skip existing
                for (int i = 0; i < Languages.Count; i++)
                {
                    //Check if content has language id
                    if (!Contents.Any(c => c.LanguageId == Languages[i].Id))
                    {
                        //Add new content object to list if none found
                        Contents.Add(new Content
                        {
                            Language   = Languages[i],
                            LanguageId = Languages[i].Id,
                            PostId     = Post.Id
                        });
                    }
                }
                _context.Update(Post);
                _context.SaveChanges();
            }
            Post.Content = Contents;
            Console.WriteLine(string.Empty);
            return(Page());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Title,ReleaseDate,Label,Body")] Blog blog)
        {
            if (id != blog.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(blog);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BlogExists(blog.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(blog));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Edit(Guid id, [Bind("Id,Paragraph")] AboutMe aboutMe)
        {
            if (id != aboutMe.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(aboutMe);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AboutMeExists(aboutMe.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(aboutMe));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Edit(Guid id, [Bind("Id,InfoAboutMe,InfoAboutStudy,AboutWork,Achievement,Image")] Portfolio portfolio)
        {
            if (id != portfolio.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(portfolio);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PortfolioExists(portfolio.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(portfolio));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,ContactName,Email,Message,Location")] ContactUsMessage contactUsMessage)
        {
            if (id != contactUsMessage.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(contactUsMessage);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ContactUsMessageExists(contactUsMessage.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(contactUsMessage));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Edit(string id, [Bind("Name")] Technology technology)
        {
            if (id != technology.Name)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(technology);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TechnologyExists(technology.Name))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(technology));
        }
        public async Task <IActionResult> Edit(Guid id, [Bind("Id,ImagePath,Text")] Project project)
        {
            if (id != project.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(project);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProjectExists(project.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(project));
        }
Ejemplo n.º 8
0
        public void EditBlog(int id, BlogViewModel blog)
        {
            var context = new PortfolioContext();

            var entryBlog = new Blog
            {
                BlogId           = id,
                Title            = blog.Title,
                Tags             = blog.Tags,
                DateSubmitted    = blog.DateSubmitted,
                SystemChangeDate = DateTime.Today,
                Content          = blog.Content
            };

            context.Update(entryBlog);
            context.SaveChanges();
        }
        public async Task <IActionResult> Edit(CreateUser authorization)
        {
            int    idCookie       = 0;
            string statusPassword = "";

            if (Request.Cookies.ContainsKey("IdUser") && Request.Cookies.ContainsKey("UserPassword"))
            {
                idCookie       = int.Parse(Request.Cookies["IdUser"]);
                statusPassword = Request.Cookies["UserPassword"];
            }

            if (statusPassword == "true" && idCookie > 0)
            {
                var userAuthorization = await _context.UserAuthorization.FindAsync(idCookie);


                if (userAuthorization.HashPassword == authorization.password)
                {
                    userAuthorization.HashPassword = authorization.password1;
                }
                else
                {
                    ViewBag.er = "Неправильно введен старый пароль";
                    return(View());
                }

                _context.Update(userAuthorization);
                await _context.SaveChangesAsync();

                return(Redirect("/UserProfiles/Myprofile"));
            }
            else
            {
                return(Redirect("/UserProfile/Index"));
            }
        }
        public async Task <IActionResult> Create(BlogUser blogUser, IFormFileCollection files)
        {
            int    id             = 0;
            string statusPassword = "";

            if (Request.Cookies.ContainsKey("IdUser") && Request.Cookies.ContainsKey("UserPassword"))
            {
                id             = int.Parse(Request.Cookies["IdUser"]);
                statusPassword = Request.Cookies["UserPassword"];
            }

            if (statusPassword == "true" && id > 0)
            {
                if (ModelState.IsValid)
                {
                    blogUser.DateBlog = DateTime.Now;
                    blogUser.IdUser   = id;
                    _context.Add(blogUser);
                    await _context.SaveChangesAsync();
                }
                else
                {
                    return(View(blogUser));
                }

                ImgBlog img = new ImgBlog();

                int count = 0;
                count = _context.BlogUser.Max(p => p.IdBlog);

                foreach (var file in files)
                {
                    if (file != null)
                    {
                        byte[] imageData = null;

                        using (var fileStream = file.OpenReadStream())
                            using (var ms = new MemoryStream())
                            {
                                fileStream.CopyTo(ms);
                                imageData = ms.ToArray();
                            }

                        string type = file.ContentType;
                        img.IdBlog  = count;
                        img.IdImg   = 0;
                        img.DataImg = imageData;
                        img.IdUser  = id;
                        img.TypeImg = type;

                        _context.Add(img);
                    }
                    await _context.SaveChangesAsync();

                    int lastIdImg = _context.ImgBlog.Max(p => p.IdImg);
                    int lastBlog  = _context.BlogUser.Max(p => p.IdBlog);
                    var blog      = _context.BlogUser.Find(lastBlog);
                    blog.MainImg = lastIdImg;
                    _context.Update(blog);
                    await _context.SaveChangesAsync();
                }
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                return(Redirect("/UserAuthorization/Index"));
            }
        }
        public async Task <IActionResult> Edit(int id, FullUser fullUser, IFormFileCollection files)
        {
            int    idCookie       = 0;
            string statusPassword = "";

            if (Request.Cookies.ContainsKey("IdUser") && Request.Cookies.ContainsKey("UserPassword"))
            {
                idCookie       = int.Parse(Request.Cookies["IdUser"]);
                statusPassword = Request.Cookies["UserPassword"];
            }

            if (statusPassword == "true" && idCookie > 0)
            {
                if (id != fullUser.OneUser.IdUser)
                {
                    return(NotFound());
                }

                if (ModelState.IsValid)
                {
                    if (fullUser.BiographyUser != null)
                    {
                        fullUser.BiographyUser.IdUser = id;
                    }
                    _context.Update(fullUser.BiographyUser);
                    if (fullUser.EducationUser != null)
                    {
                        fullUser.EducationUser.IdUser = id;
                    }
                    _context.Update(fullUser.EducationUser);
                    if (fullUser.OneUser != null)
                    {
                        _context.Update(fullUser.OneUser);
                    }
                    if (fullUser.ServicesUser != null)
                    {
                        fullUser.ServicesUser.IdUser = id;
                    }
                    _context.Update(fullUser.ServicesUser);
                    if (fullUser.WorkplaceUser != null)
                    {
                        fullUser.WorkplaceUser.IdUser = id;
                    }
                    _context.Update(fullUser.WorkplaceUser);

                    await _context.SaveChangesAsync();
                }
                else
                {
                    return(View(fullUser));
                }

                ImgUser img = new ImgUser();

                foreach (var file in files)
                {
                    if (file != null)
                    {
                        byte[] imageData = null;

                        using (var fileStream = file.OpenReadStream())
                            using (var ms = new MemoryStream())
                            {
                                fileStream.CopyTo(ms);
                                imageData = ms.ToArray();
                            }


                        string type = file.ContentType;
                        img.IdUser  = id;
                        img.IdImg   = 0;
                        img.DataImg = imageData;
                        img.TypeImg = type;

                        _context.Add(img);
                    }
                    await _context.SaveChangesAsync();

                    int lastIdImg = _context.ImgUser.Where(p => p.IdUser == idCookie).Max(p => p.IdImg);
                    var profile   = _context.UserProfile.Find(idCookie);
                    profile.MainImg = lastIdImg;
                    _context.Update(profile);
                    await _context.SaveChangesAsync();
                }
                return(RedirectToRoute(new
                {
                    controller = "UserProfiles",
                    action = "Details",
                    id = id
                }));
            }
            else
            {
                return(Redirect("/UserAuthorization/Index"));
            }
        }