Exemplo n.º 1
0
        public ActionResult Create([Bind(Include = "ID,Name,Description,Owner")] Book book)
        {
            if (ModelState.IsValid)
            {
                db.Books.Add(book);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(book));
        }
Exemplo n.º 2
0
        public ActionResult Create([Bind(Include = "Id,Name,Email,Content")] Guestbook guestbook)
        {
            if (ModelState.IsValid)
            {
                db.Guestbooks.Add(guestbook);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(guestbook));
        }
Exemplo n.º 3
0
        public ActionResult Create([Bind(Include = "ID,Name")] Face face)
        {
            if (ModelState.IsValid)
            {
                db.Faces.Add(face);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(face));
        }
Exemplo n.º 4
0
        public ActionResult Create([Bind(Include = "ID,Name,Comment,FaceID,BookID")] Guest guest)
        {
            if (ModelState.IsValid)
            {
                db.Guests.Add(guest);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.BookID = new SelectList(db.Books, "ID", "Name", guest.BookID);
            ViewBag.FaceID = new SelectList(db.Faces, "ID", "Name", guest.FaceID);
            return(View(guest));
        }
        protected void RegistrationClick(object sender, EventArgs e)
        {
            if (IsValid)
            {
                try
                {
                    using (GuestBookContext context = new GuestBookContext())
                    {
                        User newUser = new User();
                        newUser.FirstName = FirstName.Value;
                        newUser.LastName  = LastName.Value;
                        newUser.Email     = Email.Value;
                        newUser.Login     = Login.Value;
                        try
                        {
                            // шифруем пароль
                            newUser.Password = EncryptionUtility.EncryptData(Password.Value);
                        }
                        catch (Exception)
                        {
                            Response.Write("<h2>Возникла ошибка при шифровании!</h2>");
                        }

                        context.Users.Add(newUser);
                        context.SaveChanges();
                        // в случай успешной регистрации пользователь будет переадресован на страничку входа
                        Response.Redirect("login.aspx");
                    }
                }
                catch (Exception)
                {
                    Response.Write("<h2>Возникла ошибка при регистрации!</2>");
                }
            }
        }
        //  [HttpPost]
        public ActionResult Create(GuestBookEntity guestBook)
        {
            guestBook.DateAdd = DateTime.Now;

            ctx.Entries.Add(guestBook);

            ctx.SaveChanges();

            return(View());
        }
Exemplo n.º 7
0
 protected void AddComment_Click(object sender, EventArgs e)
 {
     try
     {
         using (GuestBookContext context = new GuestBookContext())
         {
             TextBox textBox = (TextBox)LoginView1.FindControl("comment");
             Comment comm    = new Comment();
             comm.Date        = DateTime.Now;
             comm.CommentBody = textBox.Text;
             string str  = User.Identity.Name.Replace("!", "");
             User   user = context.Users.Where(x => x.Login == str).FirstOrDefault();
             comm.UserId = user.Id;
             context.Comments.Add(comm);
             context.SaveChanges();
             textBox.Text = "";
         }
     }
     catch (Exception ex)
     {
         string str = string.Format("<h1>{0}</h1>", ex.Message);
         Response.Write(str);
     }
 }