public IActionResult OnPost()
 {
     //TODO: Integrate checking if title/entry already exists. If so, give alert.
     Post.Modified = Post.Created = DateTime.Now;
     Post.Public   = false;
     _context.Add(Post);
     _context.SaveChanges();
     return(RedirectToPage($"/PostEdit", new { Id = Post.Id }));
 }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("Id,ContactName,Email,Message,Location")] ContactUsMessage contactUsMessage)
        {
            if (ModelState.IsValid)
            {
                _context.Add(contactUsMessage);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(contactUsMessage));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("ID,Title,ReleaseDate,Label,Body")] Blog blog)
        {
            if (ModelState.IsValid)
            {
                _context.Add(blog);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(blog));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("Name")] Technology technology)
        {
            if (ModelState.IsValid)
            {
                _context.Add(technology);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(technology));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("Id,Paragraph")] AboutMe aboutMe)
        {
            if (ModelState.IsValid)
            {
                aboutMe.Id = Guid.NewGuid();
                _context.Add(aboutMe);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(aboutMe));
        }
        public async Task <IActionResult> Create([Bind("Id,ImagePath,Text")] Project project)
        {
            if (ModelState.IsValid)
            {
                project.Id = Guid.NewGuid();
                _context.Add(project);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(project));
        }
 public Holding CreateHolding(Holding holding)
 {
     try
     {
         _ctx.Add(holding);
         _ctx.SaveChanges();
         return(holding);
     }
     catch (Exception ex)
     {
         _logger.LogError($"Error creating holding for user {holding?.UserId}", ex);
         throw;
     }
 }
Exemplo n.º 8
0
        public void CreateComment(CommentViewModel comment)
        {
            var context      = new PortfolioContext();
            var entryComment = new Comment()
            {
                BlogId        = comment.BlogId,
                DateSubmitted = comment.DateSubmitted,
                Name          = comment.Name,
                Email         = comment.Email,
                CommentText   = comment.CommentText
            };

            context.Add(entryComment);
            context.SaveChanges();
        }
Exemplo n.º 9
0
        public void CreateBlog(BlogViewModel blog)
        {
            var context   = new PortfolioContext();
            var entryBlog = new Blog
            {
                BlogId           = blog.BlogId,
                DateSubmitted    = blog.DateSubmitted,
                SystemChangeDate = DateTime.Today,
                Title            = blog.Title,
                Content          = blog.Content,
                Tags             = blog.Tags
            };

            context.Add(entryBlog);
            context.SaveChanges();
        }
        public async Task <IActionResult> Create(CreateUser authorization)
        {
            UserAuthorization userAuthorization = new UserAuthorization();

            userAuthorization.LoginUser    = authorization.LoginUser;
            userAuthorization.HashPassword = authorization.password1; // GetHash.NewHash(authorization.password1);

            if (ModelState.IsValid)
            {
                _context.Add(new UserProfile {
                    NameUser = "******"
                });
                _context.Add(new Education {
                    EducationalInstitution = " "
                });
                _context.Add(new UserServices {
                    NameServices = " "
                });
                _context.Add(new UserWorkplace {
                    UserPosition = " "
                });
                _context.Add(new UserBiography {
                    UserHistory = " "
                });
                _context.Add(userAuthorization);
                await _context.SaveChangesAsync();

                await EmailService.SendEmailAsync("*****@*****.**", "Новый пользователь", authorization.LoginUser);

                ViewBag.Nice = "Регистрация прошла успешно, войдите в систему используя свой логин и пароль";
                return(View("Index"));
            }
            else
            {
                ViewBag.er = "Что то пошло не так!";
                return(View());
            }
        }
        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"));
            }
        }