Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // GET: Worts/Details
- public ActionResult Details(int? id)
- {
- if (id == null)
- {
- return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
- }
- var wort = (from s in db.Worts
- where s.ID == id
- select s).FirstOrDefault();
- if (wort == null)
- {
- return HttpNotFound();
- }
- return View(wort);
- }
- // GET: Worts/Create
- public ActionResult Create()
- {
- return View();
- }
- // POST: Worts/Create
- [HttpPost]
- [ValidateAntiForgeryToken]
- public ActionResult Create([Bind(Include = "ID,Title,CreateDate,ClickCount,DislikeCount,LikeCount, Creator_ID")] Wort wort)
- {
- if (ModelState.IsValid)
- {
- wort.CreateDate = DateTime.Now;
- wort.ClickCount = 0;
- wort.DislikeCount = 0;
- wort.LikeCount = 0;
- var userId = User.Identity.GetUserId();
- wort.Creator = db.Users.Where(x => x.ID == userId).FirstOrDefault();
- db.Worts.Add(wort);
- db.SaveChanges();
- try
- {
- this.mailSender.SendEmail(wort);
- return RedirectToAction("Index");
- }
- catch (Exception)
- {
- throw;
- }
- }
- return View(wort);
- }
- // GET: Worts/Edit/5
- public ActionResult Edit(int? id)
- {
- if (id == null)
- {
- return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
- }
- Wort wort = db.Worts.Find(id);
- if (wort == null)
- {
- return HttpNotFound();
- }
- return View(wort);
- }
- // POST: Worts/Edit/5
- [HttpPost]
- [ValidateAntiForgeryToken]
- public ActionResult Edit([Bind(Include = "ID,Title,CreateDate")] Wort wort)
- {
- if (ModelState.IsValid)
- {
- db.Entry(wort).State = EntityState.Modified;
- db.SaveChanges();
- return RedirectToAction("Index");
- }
- return View(wort);
- }
- // GET: Worts/Delete/5
- public ActionResult Delete(int? id)
- {
- if (id == null)
- {
- return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
- }
- Wort wort = db.Worts.Find(id);
- if (wort == null)
- {
- return HttpNotFound();
- }
- return View(wort);
- }
- // POST: Worts/Delete/5
- [HttpPost, ActionName("Delete")]
- [ValidateAntiForgeryToken]
- public ActionResult DeleteConfirmed(int id)
- {
- Wort wort = db.Worts.Find(id);
- db.Worts.Remove(wort);
- db.SaveChanges();
- return RedirectToAction("Index");
- }
- [TestMethod]
- public void Details()
- {
- // Arrange
- WortsController controller = new WortsController();
- int id = 22;
- // Act
- ViewResult result = controller.Details(id) as ViewResult;
- // Assert
- Assert.IsNotNull("Details", result.ViewName);
- }
- [TestMethod]
- public void Create()
- {
- // Arrange
- WortsController controller = new WortsController();
- // Act
- ViewResult result = controller.Create(new LikeWort.Models.Wort()) as ViewResult;
- // Assert
- Assert.IsNotNull(result);
- }
- [TestMethod]
- public void Edit(int? id)
- {
- // Arrange
- WortsController controller = new WortsController();
- // Act
- ViewResult result = controller.Edit(id) as ViewResult;
- // Assert
- Assert.IsNotNull(result);
- }
- [TestMethod]
- public void Delete(int? id)
- {
- // Arrange
- WortsController controller = new WortsController();
- // Act
- ViewResult result = controller.Delete(id) as ViewResult;
- // Assert
- Assert.IsNotNull(result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement