public IActionResult GetGuesbookList(string keyword, int page = 1, int limit = 20)
        {
            int numPerPage, currentPage, startRowIndex;

            numPerPage    = limit;
            currentPage   = page;
            startRowIndex = (currentPage - 1) * numPerPage;
            Expression ex = Guestbook._.Id > 0;

            if (!string.IsNullOrWhiteSpace(keyword))
            {
                if (Utils.IsInt(keyword))
                {
                    ex &= (Guestbook._.Id == int.Parse(keyword) | Guestbook._.Title.Contains(keyword));
                }
                else
                {
                    ex &= Guestbook._.Title.Contains(keyword);
                }
            }
            string kid = Request.Query["kid"];

            if (Utils.IsInt(kid) && int.Parse(kid) > 0)
            {
                ex &= Guestbook._.KId == int.Parse(kid);
            }
            IList <Guestbook> list = Guestbook.FindAll(ex, Guestbook._.Id.Desc(), null, startRowIndex, numPerPage);
            long totalCount        = Guestbook.FindCount(ex, Guestbook._.Id.Desc(), null, startRowIndex, numPerPage);

            Core.Admin.WriteLogActions("查看留言列表(page:" + page + ");");
            return(Content(Newtonsoft.Json.JsonConvert.SerializeObject(new { total = totalCount, rows = list }), "text/plain"));
        }
Example #2
0
        public IActionResult DoPostMessage(string name, string phone, string content)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                tip.Message = "请填写您的姓名!";
                return(Json(tip));
            }
            if (!Utils.IsTel(phone))
            {
                tip.Message = "请填写正确的手机号码!";
                return(Json(tip));
            }
            if (string.IsNullOrWhiteSpace(content))
            {
                tip.Message = "请填写您的留言内容!";
                return(Json(tip));
            }

            Guestbook entity = new Guestbook()
            {
                AddTime  = DateTime.Now,
                IP       = Utils.GetIP(),
                KId      = 1,
                Nickname = name,
                Content  = Utils.NoHTML(content),
                Tel      = phone
            };

            entity.Insert();

            tip.Message = "留言成功,感谢您的留言!";
            tip.Status  = JsonTip.SUCCESS;
            return(Json(tip));
        }
Example #3
0
        public static void PopulateTestData(AppDbContext dbContext)
        {
            var toDos = dbContext.ToDoItems;

            foreach (var item in toDos)
            {
                dbContext.Remove(item);
            }
            dbContext.SaveChanges();
            dbContext.ToDoItems.Add(new ToDoItem()
            {
                Title       = "Test Item 1",
                Description = "Test Description One"
            });
            dbContext.ToDoItems.Add(new ToDoItem()
            {
                Title       = "Test Item 2",
                Description = "Test Description Two"
            });

            var createdGuestbook = new Guestbook();

            createdGuestbook.Name = "My Guestbook";

            createdGuestbook.AddEntry(new GuestBookEntry()
            {
                EmailAddress = "*****@*****.**", Message = "hello world", DateTimeCreated = DateTimeOffset.UtcNow.AddHours(-2)
            });
            dbContext.Guestbooks.Add(createdGuestbook);

            dbContext.SaveChanges();
        }
Example #4
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Comment,Date,Tag")] Guestbook guestbook)
        {
            if (id != guestbook.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    guestbook.Date = DateTime.Now.Date;
                    _context.Update(guestbook);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!GuestbookExists(guestbook.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(guestbook));
        }
Example #5
0
        public IActionResult Index()
        {
            if (!_repository.List <Guestbook>().Any())
            {
                var newGuestbook = new Guestbook {
                    Name = "My Guestbook"
                };
                newGuestbook.Entries.Add(new GuestbookEntry {
                    EmailAddress = "*****@*****.**", Message = "Hi!", DateTimeCreated = DateTime.UtcNow.AddHours(-2)
                });
                newGuestbook.Entries.Add(new GuestbookEntry {
                    EmailAddress = "*****@*****.**", Message = "Hi again!", DateTimeCreated = DateTime.UtcNow.AddHours(-1)
                });
                newGuestbook.Entries.Add(new GuestbookEntry {
                    EmailAddress = "*****@*****.**", Message = "Hello!"
                });
                _repository.Add(newGuestbook);
            }

            var guestbook = _repository.GetById <Guestbook>(1); // hardcoded for this sample; could support multi-tenancy in real app
            List <GuestbookEntry> guestbookEntries = _repository.List <GuestbookEntry>();

            guestbook.Entries.Clear();                    // remove in-memory Guestbook Entries
            guestbook.Entries.AddRange(guestbookEntries); // Fetch Entries from database.
            var viewModel = new HomePageViewModel();

            viewModel.GuestbookName = guestbook.Name;
            viewModel.PreviousEntries.AddRange(guestbook.Entries);
            return(View(viewModel));
        }
Example #6
0
 public IActionResult AddEntry(GuestbookMixModel model)
 {
     if (ModelState.IsValid)
     {
         if (ReCaptchaPassed(Request.Form["g-recaptcha-response"], _configuration.GetSection("GoogleReCaptcha:secret").Value))
         {
             var entry = new Guestbook();
             entry.GuestbookComment     = model.Guestbook.GuestbookComment;
             entry.GuestbookUser        = model.Guestbook.GuestbookUser;
             entry.GuestbookUserEmail   = model.Guestbook.GuestbookUserEmail;
             entry.GuestbookUserWebsite = model.Guestbook.GuestbookUserWebsite;
             entry.GuestbookDate        = DateTime.Now;
             entry.GuestbookIP          = HttpContext.Connection.RemoteIpAddress.ToString();
             entry.GuestbookApproved    = "No";
             _db.Guestbook.Add(entry);
             _db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         else
         {
             ModelState.AddModelError(string.Empty, "Sorry, you failed the ReCaptcha check.");
             return(View(model));
         }
     }
     return(View("Index"));
 }
        public static int SeedAsync(GuestbookDbContext context)
        {
            // Use the Migrate method to automatically create the database and migrat if needed
            context.Database.EnsureCreated();

            if (context.Guestbooks.Count() == 0)
            {
                // we could also check for some specific instances and behave accordingly to the result.
                Guestbook guestbook = new Guestbook {
                    Name = "Novia guestbook"
                };
                IGuestbookEntry firstEntry = new GuestbookEntry
                {
                    Message = "Welcome to Novia!"
                };
                guestbook.AddEntry(firstEntry);
                IGuestbookEntry secondEntry = new GuestbookEntry
                {
                    Message = "IT profile salutes you."
                };
                guestbook.AddEntry(secondEntry);

                context.Guestbooks.Add(guestbook);
                return(context.SaveChanges());
            }
            return(0);
        }
        public static void PopulateTestData(AppDbContext dbContext)
        {
            var toDos = dbContext.ToDoItems;

            foreach (var item in toDos)
            {
                dbContext.Remove(item);
            }
            dbContext.SaveChanges();
            dbContext.ToDoItems.Add(new ToDoItem()
            {
                Title       = "Test Item 1",
                Description = "Test Description One"
            });
            dbContext.ToDoItems.Add(new ToDoItem()
            {
                Title       = "Test Item 2",
                Description = "Test Description Two"
            });
            dbContext.SaveChanges();

            // add Guestbook test data; specify Guestbook ID for use in tests
            var guestbook = new Guestbook {
                Name = "Test Guestbook", Id = 1
            };

            dbContext.Guestbooks.Add(guestbook);
            guestbook.AddEntry(new GuestbookEntry
            {
                EmailAddress = "*****@*****.**",
                Message      = "Test message"
            });
            guestbook.Events.Clear();
            dbContext.SaveChanges();
        }
        public IHttpActionResult PutGuestbook(int id, Guestbook guestbook)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != guestbook.Id)
            {
                return(BadRequest());
            }

            db.Entry(guestbook).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GuestbookExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
 public ActionResult CreateGuest(Guestbook entry)
 {
     entry.Дата = DateTime.Now;
     db.Guestbooks.Add(entry);
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }
Example #11
0
        public static void PopulateTestData(AppDbContext dbContext)
        {
            var guestbook = new Guestbook()
            {
                Name = "Test Guestbook", Id = 1
            };

            dbContext.Guestbooks.Add(guestbook);
            guestbook.Entries.Add(new GuestbookEntry()
            {
                EmailAddress = "*****@*****.**",
                Message      = "Test message"
            });
            dbContext.SaveChanges();

            var toDos = dbContext.ToDoItems;

            foreach (var item in toDos)
            {
                dbContext.Remove(item);
            }
            dbContext.SaveChanges();
            dbContext.ToDoItems.Add(new ToDoItem()
            {
                Title       = "Test Item 1",
                Description = "Test Description One"
            });
            dbContext.ToDoItems.Add(new ToDoItem()
            {
                Title       = "Test Item 2",
                Description = "Test Description Two"
            });
            dbContext.SaveChanges();
        }
Example #12
0
        public static void PopulateTestData(AppDbContext dbContext)
        {
            foreach (var item in dbContext.ToDoItems)
            {
                dbContext.Remove(item);
            }
            dbContext.SaveChanges();
            dbContext.ToDoItems.Add(ToDoItem1);
            dbContext.ToDoItems.Add(ToDoItem2);
            dbContext.ToDoItems.Add(ToDoItem3);

            dbContext.SaveChanges();

            // add Guestbook test data; specify Guestbook ID for use in tests
            var guestbook = new Guestbook()
            {
                Name = "Test Guestbook", Id = 1
            };

            dbContext.Guestbooks.Add(guestbook);
            guestbook.AddEntry(new GuestbookEntry
            {
                EmailAddress = "*****@*****.**",
                Message      = "Test message"
            });
            guestbook.Events.Clear();
            dbContext.SaveChanges();
        }
Example #13
0
        private void PopulateTestData(IApplicationBuilder app)
        {
            var dbContext = app.ApplicationServices.GetService <AppDbContext>();

            // reset the database
            dbContext.Database.EnsureDeleted();

            dbContext.ToDoItems.Add(new ToDoItem()
            {
                Title       = "Test Item 1",
                Description = "Test Description One"
            });
            dbContext.ToDoItems.Add(new ToDoItem()
            {
                Title       = "Test Item 2",
                Description = "Test Description Two"
            });
            dbContext.SaveChanges();

            // add Guestbook test data; specify Guestbook ID for use in tests
            var guestbook = new Guestbook()
            {
                Name = "Test Guestbook", Id = 1
            };

            dbContext.Guestbooks.Add(guestbook);
            guestbook.AddEntry(new GuestbookEntry()
            {
                EmailAddress = "*****@*****.**",
                Message      = "Test message"
            });
            dbContext.SaveChanges();
        }
        public IActionResult Index()
        {
            if (!_repository.List <Guestbook>().Any())
            {
                var newGuestbook = new Guestbook {
                    Name = "My Guestbook"
                };
                newGuestbook.AddEntry(new GuestbookEntry {
                    EmailAddress = "*****@*****.**", Message = "Hi!", DateTimeCreated = DateTime.UtcNow.AddHours(-2)
                });
                newGuestbook.AddEntry(new GuestbookEntry {
                    EmailAddress = "*****@*****.**", Message = "Hi again!", DateTimeCreated = DateTime.UtcNow.AddHours(-1)
                });
                newGuestbook.AddEntry(new GuestbookEntry {
                    EmailAddress = "*****@*****.**", Message = "Hello!"
                });
                newGuestbook.Events.Clear();
                _repository.Add(newGuestbook);
            }

            var guestbook = _repository.GetById <Guestbook>(1); // hardcoded for this sample; could support multi-tenancy in real app
            var viewModel = new HomePageViewModel();

            viewModel.GuestbookName = guestbook.Name;
            viewModel.PreviousEntries.AddRange(guestbook.Entries
                                               .Select(e => new GuestbookEntryDTO
            {
                DateTimeCreated = e.DateTimeCreated,
                EmailAddress    = e.EmailAddress,
                Id      = e.Id,
                Message = e.Message
            }));
            return(View(viewModel));
        }
Example #15
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        string Code = Session["image"].ToString().Trim();  //验证码
        string Txtbox =HttpUtility.HtmlEncode(this.TextBox2.Text).ToString().Trim();
        if (TextBox1.Text != "")
        {
            if (Code == Txtbox.ToUpper())
            {
                using (var db = new ItshowEntities2())
                {
                    string New_Message;
                    New_Message = HttpUtility.HtmlEncode(TextBox1.Text);
                    var guidebook = new Guestbook();

                    guidebook.Contents = New_Message;
                    guidebook.Puttime = DateTime.Now.ToString();
                    db.Guestbooks.Add(guidebook);
                    db.SaveChanges();
                    Response.Write("<script>alert('留言提交成功,请耐心等待审核结果!');</script>");
                    TextBox1.Text = null;
                    TextBox2.Text = null;
                }
            }
            else
                Response.Write("<script>alert('验证码不正确,请重新输入!');</script>");
        }
        else
            Response.Write("<script>alert('主要内容不能为空!');</script>");
    }
Example #16
0
        public ActionResult Index(string Search = "", int page = 1)
        {
            Guestbook IndexViewModel = new Guestbook();

            IndexViewModel.ForPaging = new ForPaging(page);
            IndexViewModel.DataList  = guestbookService.GetAllGuestbooks(IndexViewModel.ForPaging, Search);
            return(View(IndexViewModel));
        }
Example #17
0
        public void InsertGuestbook(Guestbook newData)
        {
            newData.Id         = MiscHelper.ShortGuid;
            newData.CreateTime = DateTime.Now;

            _guestbookRepository.Insert(newData);
            _unitOfWork.Commit();
        }
 public ActionResult Create([Bind(Include = "Content")] Guestbook Data)
 {
     //設定新增留言者為登入者
     Data.Account = User.Identity.Name;
     //使用Service 來新增一筆資料
     GuestbookService.InsertGuestbooks(Data);
     return(RedirectToAction("Index"));
 }
Example #19
0
        public ActionResult DeleteConfirmed(int id)
        {
            Guestbook guestbook = db.Guestbooks.Find(id);

            db.Guestbooks.Remove(guestbook);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #20
0
        public ActionResult Edit(int Id)
        {
            //取得頁面所需資料,由Service取得
            Guestbook Data = GuestbookService.GetDataById(Id);

            //將資料傳入 View 中
            return(View(Data));
        }
Example #21
0
 public static GuestbookDTO FromGuestbook(Guestbook guestbook)
 {
     return(new GuestbookDTO()
     {
         Id = guestbook.Id,
         Entries = guestbook.Entries.Select(e => GuestbookEntryDTO.FromEntry(e)).ToList()
     });
 }
Example #22
0
        //修改資料判斷的方式

        public bool CheckUpdate(int Id)
        {
            //根據 Id 取得要修改的資料
            Guestbook Data = GetDataById(Id);

            //判斷並回傳
            return(Data != null && Data.ReplyTime == null);
        }
Example #23
0
        public bool Update(int guestbookID, bool display)
        {
            Guestbook guestbook = Get(guestbookID);

            using (SprocWrapper db = new SprocWrapper())
            {
                return(db.Guestbook_Update(guestbookID, guestbook.Name, guestbook.Email, guestbook.Comment, guestbook.Reply, display));
            }
        }
Example #24
0
        public ActionResult DelGB(int guestbookID)
        {
            Guestbook deletedGB = repository.DeleteGuestbook(guestbookID);

            if (deletedGB != null)
            {
                TempData["message"] = string.Format("Отзыв'{0}' удален", deletedGB.Name);
            }
            return(RedirectToAction("Guest"));
        }
Example #25
0
 public ActionResult Edit([Bind(Include = "Id,Name,Email,Content")] Guestbook guestbook)
 {
     if (ModelState.IsValid)
     {
         db.Entry(guestbook).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(guestbook));
 }
        public Guestbook DeleteGuestbook(int guestbookID)
        {
            Guestbook dbGB = context.Guestbooks.Find(guestbookID);

            if (dbGB != null)
            {
                context.Guestbooks.Remove(dbGB);
                context.SaveChanges();
            }
            return(dbGB);
        }
Example #27
0
        public void ReplyGuestbook(Guestbook replyData)
        {
            var entity = GetDataById(replyData.Id);

            entity.Reply     = replyData.Reply;
            entity.ReplyTime = DateTime.Now;
            entity.ReplierId = replyData.ReplierId;

            _guestbookRepository.Update(entity);
            _unitOfWork.Commit();
        }
Example #28
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));
        }
Example #29
0
        public void DeleteGuestbook(string Id, string userId)
        {
            Guestbook entity = GetDataById(Id);

            entity.UpdaterId  = userId;
            entity.UpdateTime = DateTime.Now;
            entity.IsDelete   = true;

            _guestbookRepository.Update(entity);
            _unitOfWork.Commit();
        }
        public IHttpActionResult GetGuestbook(int id)
        {
            Guestbook guestbook = db.Guestbooks.Find(id);

            if (guestbook == null)
            {
                return(NotFound());
            }

            return(Ok(guestbook));
        }
Example #31
0
        public ActionResult Write(Guestbook guestbook)
        {
            if (ModelState.IsValid)
            {
                db.Guestbooks.Add(guestbook);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(guestbook));
        }
        private Guestbook ParseGuestbookNode(XmlNode guestbookNode)
        {
            try {
                Guestbook guestbook = new Guestbook();

                foreach (XmlNode xmlNode in guestbookNode.ChildNodes) {
                    switch (xmlNode.Name) {
                        case Tags.NumberOfGuestbookItems:
                            guestbook.numberOfGuestbookItemsField = GenericFunctions.ConvertStringToUInt(xmlNode.InnerText);
                            break;
                    }
                }

                return guestbook;
            } catch (Exception ex) {
                throw ex;
            }
        }