0% found this document useful (0 votes)
28 views

using System

test case kiểm thử phần mềm

Uploaded by

Vnice
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

using System

test case kiểm thử phần mềm

Uploaded by

Vnice
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

using System;

using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace WebsiteNoiThat.Areas.Admin.Controllers
{
public class HomeController : Controller
{
// GET: Admin/Home
public ActionResult Index()
{
var session =
(UserLogin)Session[WebsiteNoiThat.Common.Commoncontent.user_sesion_admin];
if ( session != null)
{
ViewBag.username = session.Username;
return View();

}
else
{
return Redirect("~/Admin/Login");
}
}
//public ActionResult Show()
//{
// var session =
(UserLogin)Session[WebsiteNoiThat.Common.Commoncontent.user_sesion_admin];
// if (session != null)
// {
// ViewBag.username = session.Username;
// return View();

// }
// else
// {
// return Redirect("~/Admin/Login");
// }
//}

}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebsiteNoiThat.Areas.Admin.Models;
using Models.DAO;
using WebsiteNoiThat.Common;
using System.Web.Security;

namespace WebsiteNoiThat.Areas.Admin.Controllers
{
public class LoginController : Controller
{
// GET: Admin/Login
public ActionResult Index()
{
return View();
}

[HttpPost]
public ActionResult Login(LoginModel model)
{
if (ModelState.IsValid)
{
var dao = new UserDao();
// var result = dao.Login(model.Username, Encryptor.MD5Hash(model.Passwword),
true);
var result = dao.Login(model.Username, model.Passwword, true);
if (result == 1)
{
var user = dao.GetById(model.Username);
var userSession = new UserLogin();
userSession.Username = user.Username;
userSession.UserId = user.UserId;
Session["UserId"] = user.UserId.ToString();
userSession.GroupId = user.GroupId;
var listCredentials = dao.GetListCredentials(model.Username);
Session.Add(Commoncontent.SESSION_CREDENTIALS, listCredentials);
Session.Add(Commoncontent.user_sesion_admin, userSession);
return RedirectToAction("Index", "Home");
}
else if (result == 0)
{
ModelState.AddModelError("", "Tài Khoản không tồn tại!");

}
else if (result == -1)
{
ModelState.AddModelError("", "Tài Khoản đang bị khóa!");
}
else if (result == -2)
{
ModelState.AddModelError("", "Mật khẩu không đúng!");
}
else if (result == -3)
{
ModelState.AddModelError("", "Tài khoản của bạn không có quyền đăng nhập.");
}
}

return View("Index");
}
public ActionResult Logout()
{
Session[Commoncontent.user_sesion_admin] = null;
Session[Commoncontent.SESSION_CREDENTIALS] = null;
FormsAuthentication.SignOut();
return RedirectToAction("Index","Login");
}
}
}
using Models.DAO;
using Models.EF;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebsiteNoiThat.Common;
using WebsiteNoiThat.Models;

namespace WebsiteNoiThat.Areas.Admin.Controllers
{
public class ProductController : HomeController
{
DBNoiThat db = new DBNoiThat();

[HasCredential(RoleId = "VIEW_PRODUCT")]
public ActionResult Show()
{
var session =
(UserLogin)Session[WebsiteNoiThat.Common.Commoncontent.user_sesion_admin];
ViewBag.username = session.Username;

var productViewModels = (from a in db.Products


join b in db.Providers on a.ProviderId equals b.ProviderId
join c in db.Categories on a.CateId equals c.CategoryId
select new ProductViewModel
{
ProductId = a.ProductId,
Name = a.Name,
Description = a.Description,
Discount = a.Discount,
ProviderName = b.Name,
CateName = c.Name,
Price = a.Price,
Quantity = a.Quantity,
StartDate = a.StartDate,
EndDate = a.EndDate,
Photo = a.Photo,
}).ToList();

return View(productViewModels);
}

[HttpGet]
[HasCredential(RoleId = "ADD_PRODUCT")]
public ActionResult Add()
{
var session =
(UserLogin)Session[WebsiteNoiThat.Common.Commoncontent.user_sesion_admin];
ViewBag.username = session.Username;

ViewBag.ListCate = new SelectList(db.Categories.ToList(), "CategoryId", "Name");


ViewBag.ListProvider = new SelectList(db.Providers.ToList(), "ProviderId", "Name");
return View();
}

[HttpPost]
[HasCredential(RoleId = "ADD_PRODUCT")]
public ActionResult Add(ProductViewModel n, HttpPostedFileBase UploadImage)
{
var session =
(UserLogin)Session[WebsiteNoiThat.Common.Commoncontent.user_sesion_admin];
ViewBag.username = session.Username;

ViewBag.ListCate = new SelectList(db.Categories.ToList(), "CategoryId", "Name");


ViewBag.ListProvider = new SelectList(db.Providers.ToList(), "ProviderId", "Name");
if (ModelState.IsValid)
{
var models = db.Products.SingleOrDefault(a => a.ProductId == n.ProductId);
if (models != null)
{
ModelState.AddModelError("ProductError", "Mã sản phẩm đã tồn tại!");
return View();
}
else
{
var fileName = Path.GetFileName(UploadImage.FileName);
var path = Path.Combine(Server.MapPath("~/image"), fileName);
UploadImage.SaveAs(path);
n.Photo = UploadImage.FileName;
var model = new Product();
model.ProductId = n.ProductId;
model.Name = n.Name;
model.Photo = n.Photo;
model.Price = n.Price;
model.Quantity = n.Quantity;
model.StartDate = n.StartDate;
model.EndDate = n.EndDate;
model.CateId = n.CateId;
model.ProductId = n.ProductId;
model.Description = n.Description;
if (n.Discount == null)
{
model.Discount = 0;
}
else
{
model.Discount = n.Discount;
}
model.ProviderId = n.ProviderId;
db.Products.Add(model);
db.SaveChanges();
}
}
else
{
ModelState.AddModelError("ErrorDate", "Ngày kết thúc phải muộn hơn ngày bắt đầu.");
return View();

return RedirectToAction("Show");
}

[HttpGet]
[HasCredential(RoleId = "EDIT_PRODUCT")]
public ActionResult Edit(int ProductId)
{
var session =
(UserLogin)Session[WebsiteNoiThat.Common.Commoncontent.user_sesion_admin];
ViewBag.username = session.Username;

var model = (from a in db.Products


join b in db.Providers on a.ProviderId equals b.ProviderId
join c in db.Categories on a.CateId equals c.CategoryId
where a.ProductId == ProductId
select new ProductViewModel
{
ProductId = a.ProductId,
Name = a.Name,
Description = a.Description,
Discount = a.Discount,
ProviderName = b.Name,
CateName = c.Name,
Price = a.Price,
Quantity = a.Quantity,
StartDate = a.StartDate,
EndDate = a.EndDate,
Photo = a.Photo,
CateId = a.CateId
}).ToList();

ViewBag.ListCate = new SelectList(db.Categories.ToList(), "CategoryId", "Name");


ViewBag.ListProvider = new SelectList(db.Providers.ToList(), "ProviderId", "Name");
var models = model.Where(n => n.ProductId == ProductId).First();
return View(models);
}

[HttpPost]
[HasCredential(RoleId = "EDIT_PRODUCT")]
public ActionResult Edit(ProductViewModel n, HttpPostedFileBase UploadImage)

{
var session =
(UserLogin)Session[WebsiteNoiThat.Common.Commoncontent.user_sesion_admin];
ViewBag.username = session.Username;

ViewBag.ListCate = new SelectList(db.Categories.ToList(), "CategoryId", "Name");


ViewBag.ListProvider = new SelectList(db.Providers.ToList(), "ProviderId", "Name");
if (ModelState.IsValid)
{
ProductDao a = new ProductDao();
if (UploadImage != null)
{
// Delete exiting file
//System.IO.File.Delete(Path.Combine(Server.MapPath("~/image"), n.Photo));
// Save new file
string fileName = Path.GetFileName(UploadImage.FileName);
string path = Path.Combine(Server.MapPath("~/image"), fileName);
UploadImage.SaveAs(path);
n.Photo = fileName;

}
var model = db.Products.FirstOrDefault(m => m.ProductId == n.ProductId);
model.ProductId = n.ProductId;
model.Name = n.Name;
model.Photo = n.Photo;
model.Price = n.Price;
model.Quantity = n.Quantity;
model.StartDate = n.StartDate;
model.EndDate = n.EndDate;
model.CateId = model.CateId;
model.ProductId = n.ProductId;
model.Description = n.Description;
model.Discount = n.Discount;
model.ProviderId = n.ProviderId;
db.SaveChanges();
return RedirectToAction("Show", new { CateId = n.CateId });
}
else
{
ModelState.AddModelError("", "Ngày kết thúc phải muộn hơn ngày bắt đầu");
return View();
}
}

//[HttpGet]
//[HasCredential(RoleId = "DELETE_PRODUCT")]
//public ActionResult Delete()
//{
// var session =
(UserLogin)Session[WebsiteNoiThat.Common.Commoncontent.user_sesion_admin];
// ViewBag.username = session.Username;
// return View();
//}
[HttpGet]
[HasCredential(RoleId = "DELETE_PRODUCT")]
public ActionResult Delete(int id)
{
var model = db.Products.Find(Convert.ToInt32(id));
db.Products.Remove(model);
db.SaveChanges();
return View();
}

public ActionResult Menu()


{
var session =
(UserLogin)Session[WebsiteNoiThat.Common.Commoncontent.user_sesion_admin];
ViewBag.username = session.Username;

var model = new CategoryDao().ListCategory();


return PartialView(model);
}
}
}
using Models.EF;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebsiteNoiThat.Common;

namespace WebsiteNoiThat.Areas.Admin.Controllers
{
public class ProviderController : HomeController
{
// GET: Admin/Provider
DBNoiThat db = new DBNoiThat();

[HasCredential(RoleId = "VIEW_PROVIDER")]
public ActionResult Index()
{
return View();
}

[HasCredential(RoleId = "VIEW_PROVIDER")]
public ActionResult Show()
{
return View(db.Providers.ToList());
}

[HttpGet]
[HasCredential(RoleId = "ADD_PROVIDER")]
public ActionResult Add()
{
return View();
}
[HttpPost]
[HasCredential(RoleId = "ADD_PROVIDER")]
public ActionResult Add(Provider n)
{
var model = db.Providers.SingleOrDefault(a => a.ProviderId == n.ProviderId);
if (model != null)
{
ModelState.AddModelError("ProError", "Id already in use");
return View();
}
else
{
db.Providers.Add(n);
db.SaveChanges();
return RedirectToAction("Show");
}

}
[HttpGet]
[HasCredential(RoleId = "EDIT_PROVIDER")]
public ActionResult Edit(int ProviderId)
{
Provider a = db.Providers.SingleOrDefault(n => n.ProviderId == ProviderId);
if (a == null)
{
Response.StatusCode = 404;
return RedirectToAction("Show");
}
return View(a);

[HttpPost]
[HasCredential(RoleId = "EDIT_PROVIDER")]
public ActionResult Edit(Provider n)
{
if (ModelState.IsValid)
{
db.Entry(n).State = System.Data.Entity.EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Show");
}
else
{
return JavaScript("alert('Error');");
}
}

[HttpGet]
[HasCredential(RoleId = "DELETE_PROVIDER")]
public ActionResult Delete(int id)
{
var model = db.Providers.Find(Convert.ToInt32(id));
db.Providers.Remove(model);
db.SaveChanges();
return RedirectToAction("Show");
}

}
}

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using Models.EF;
using WebsiteNoiThat.Common;

namespace WebsiteNoiThat.Areas.Admin.Controllers
{
public class RolesController : Controller
{
private DBNoiThat db = new DBNoiThat();

// GET: Admin/Roles
[HasCredential(RoleId = "VIEW_ROLE")]
public ActionResult Index()
{
var session =
(UserLogin)Session[WebsiteNoiThat.Common.Commoncontent.user_sesion_admin];
ViewBag.username = session.Username;

return View(db.Roles.ToList());
}

// GET: Admin/Roles/Details/5
[HasCredential(RoleId = "VIEW_ROLE")]
public ActionResult Details(string id)
{
var session =
(UserLogin)Session[WebsiteNoiThat.Common.Commoncontent.user_sesion_admin];
ViewBag.username = session.Username;

if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Role role = db.Roles.Find(id);
if (role == null)
{
return HttpNotFound();
}
return View(role);
}

// GET: Admin/Roles/Create
[HasCredential(RoleId = "ADD_ROLE")]
public ActionResult Create()
{
var session =
(UserLogin)Session[WebsiteNoiThat.Common.Commoncontent.user_sesion_admin];
ViewBag.username = session.Username;

return View();
}

// POST: Admin/Roles/Create
// To protect from overposting attacks, please enable the specific properties you want to
bind to, for
// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
[HasCredential(RoleId = "ADD_ROLE")]
public ActionResult Create([Bind(Include = "RoleId,Name")] Role role)
{
if (ModelState.IsValid)
{
db.Roles.Add(role);
db.SaveChanges();
return RedirectToAction("Index");
}

return View(role);
}

// GET: Admin/Roles/Edit/5
[HasCredential(RoleId = "EDIT_ROLE")]
public ActionResult Edit(string id)
{
var session =
(UserLogin)Session[WebsiteNoiThat.Common.Commoncontent.user_sesion_admin];
ViewBag.username = session.Username;

if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Role role = db.Roles.Find(id);
if (role == null)
{
return HttpNotFound();
}
return View(role);
}

// POST: Admin/Roles/Edit/5
// To protect from overposting attacks, please enable the specific properties you want to
bind to, for
// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
[HasCredential(RoleId = "EDIT_ROLE")]
public ActionResult Edit([Bind(Include = "RoleId,Name")] Role role)
{
if (ModelState.IsValid)
{
db.Entry(role).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(role);
}

// GET: Admin/Roles/Delete/5
[HasCredential(RoleId = "DELETE_ROLE")]
public ActionResult Delete(string id)
{
var session =
(UserLogin)Session[WebsiteNoiThat.Common.Commoncontent.user_sesion_admin];
ViewBag.username = session.Username;

if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Role role = db.Roles.Find(id);
db.Roles.Remove(role);
db.SaveChanges();
return RedirectToAction("Index");
}

protected override void Dispose(bool disposing)


{
if (disposing)
{
db.Dispose();
}
base.Dispose(disposing);
}
}
}

You might also like