public Giay ThemGiay(Giay giay, IFormFile anh) { ThemAnh(giay, anh); _csdl._Giay.Add(giay); _csdl.SaveChanges(); return(giay); }
public ActionResult Create([Bind(Include = "OrderID,OrderName,OrderDate,CustomerName,CustomerPhone,CustomerEmail,CustomerAddress")] Order order) { if (ModelState.IsValid) { db.Order.Add(order); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(order)); }
public ActionResult Create([Bind(Include = "MaTG,Hinh,TenTG,TieuSu,GioiTinh")] TacGia tacGia) { if (ModelState.IsValid) { db.TacGia.Add(tacGia); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tacGia)); }
public ActionResult Create([Bind(Include = "MaPhanHoi,HoTen,Email,DiaChi,SDT,NoiDung")] PhanHoi phanHoi) { if (ModelState.IsValid) { db.PhanHoi.Add(phanHoi); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(phanHoi)); }
public ActionResult SaveOrder() { var user = Session["Account"] as Account; if (user == null) { RedirectToAction("Login", "Authentication"); } var cart = Session["Cart"] as CartViewModel; if (cart == null) { return(RedirectToAction("Index", "Book")); } var couponDefault = db.Coupon.SingleOrDefault(c => c.Code == "NULL"); int couponId = couponDefault.Id; if (cart.Coupon != null) { couponId = db.Coupon.SingleOrDefault(cp => cp.Code == cart.Coupon).Id; } var newCart = new Cart { TotalItem = cart.Items.Count, TotalPrice = cart.Total, AccountId = user.Id, CouponId = couponId, DateOrder = DateTime.Today, IsShiped = false, }; db.Cart.Add(newCart); db.SaveChanges(); foreach (var item in cart.Items) { db.CartDetail.Add(new CartDetail { BookId = item.Book.Id, CartId = newCart.Id, Quantity = item.Count }); } db.SaveChanges(); Session["Cart"] = null; // Cart for user return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "id,OrderID,Price,Quantity,Status")] OrderDetail orderDetail) { if (ModelState.IsValid) { db.OrderDetail.Add(orderDetail); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.OrderID = new SelectList(db.Order, "OrderID", "OrderName", orderDetail.OrderID); return(View(orderDetail)); }
public ActionResult Create([Bind(Include = "id,gia,tensp,hinh,mota,ttc_kichthuoc,ttc_ngayxuatban,ttc_loaibia,ttc_sotrang,ttc_nhaxuatban,motasanpham,MaDM,MaNXB")] Sach sach) { if (ModelState.IsValid) { db.Sach.Add(sach); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MaDM = new SelectList(db.DanhMuc, "MaDM", "TenDanhMuc", sach.MaDM); ViewBag.MaNXB = new SelectList(db.NhaXuatBan, "MaNXB", "TenNXB", sach.MaNXB); return(View(sach)); }
public ActionResult AddCoupon(string code, DateTime timeStart, DateTime timeEnd, int percents, string hinh) { db.Coupon.Add(new Coupon() { Code = code, TimeStart = timeStart, TimeEnd = timeEnd, Percents = percents }); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult AddNewRealse(int id) { if (db.NewRelease.Count() >= 6) { return(RedirectToAction("Index")); } db.NewRelease.Add(new NewRelease { BookId = id }); db.SaveChanges(); return(RedirectToAction("Index")); }
public void TaoDonHang(DonHang donHang) { donHang.NgayDat = DateTime.Now; donHang.TongTien = _gioHang.TinhTongTienGioHang(); _csdl._DonHang.Add(donHang); var chitietgiohang = _gioHang.ChiTietGioHang; foreach (var c in chitietgiohang) { var chitietdonhang = new ChiTietDonHang() { SoLuong = c.SoLuong, GiayID = c.Giay.GiayID, DonHangID = donHang.DonHangID, Gia = c.Giay.Gia }; _csdl._ChiTietDonHang.Add(chitietdonhang); } _csdl.SaveChanges(); }
public ActionResult Authen(string username, string password) { var user = db.Account.SingleOrDefault(u => u.UserName == username && u.Password == password); if (user == null) { return(RedirectToAction("Login")); } Session["Account"] = user; if (user.IsAdmin) { return(RedirectToAction("Index", "Admin")); } var his = new History { AccountId = user.Id, VisitedDate = DateTime.Now }; db.History.Add(his); db.SaveChanges(); // Detail user return(RedirectToAction("Index", "Home")); }
public void Themhogiadinh(hogiadinh a) { CSDL db = new CSDL(); db.hogiadinhs.Add(a); db.SaveChanges(); }
public ActionResult Delete(int id) { var user = Session["Account"] as Account; if (user.IsAdmin == false || user == null) { return(RedirectToAction("UnAuthorized", "Authentication")); } if (db.Book.SingleOrDefault(b => b.Id == id) != null) { db.Book.Remove(db.Book.SingleOrDefault(b => b.Id == id)); db.SaveChanges(); } return(RedirectToAction("Manage")); }
public void Delete_TK(int manv) { CSDL db = new CSDL(); var tk = db.taikhoans.Where(p => p.manhanvien == manv).SingleOrDefault(); db.taikhoans.Remove(tk); db.SaveChanges(); }
public void Delete(int MAHD) { CSDL db = new CSDL(); var l1 = db.hopdongs.Where(p => p.mahopdong.Equals(MAHD)).Select(p => p).FirstOrDefault(); db.hopdongs.Remove((hopdong)l1); db.SaveChanges(); }
public void Delete_NV(int manv) { CSDL db = new CSDL(); var nv = db.nhanviens.Where(p => p.manhanvien == manv).SingleOrDefault(); db.nhanviens.Remove(nv); db.SaveChanges(); }
public void XoaDichVuKhoiHD(int mahd, int madv) { CSDL db = new CSDL(); var query = db.chitiethoadons.Where(p => p.mahoadon.Equals(mahd) && p.madichvu.Equals(madv)).SingleOrDefault(); db.chitiethoadons.Remove(query); db.SaveChanges(); }
public void AddTT(ThongTin_TK s) { try { db.ThongTin_TK.Add(s); db.SaveChanges(); } catch (Exception e) { } }
public void Giamthoigian(int tg) { CSDL db = new CSDL(); var l1 = db.hopdongs.Where(p => p.dahuy == false && p.davao == true); foreach (hopdong i in l1) { i.thoigianconlai -= tg; } db.SaveChanges(); }
public void XoaDichVu(List <int> maList) { CSDL db = new CSDL(); foreach (int i in maList) { var query = db.dichvus.Where(p => p.madichvu.Equals(i)).SingleOrDefault(); db.dichvus.Remove(query); db.SaveChanges(); } }
public ActionResult Create([Bind(Include = "id,gia,tensp,hinh,mota,ttc_kichthuoc,ttc_ngayxuatban,ttc_loaibia,ttc_sotrang,ttc_nhaxuatban,motasanpham,MaDM,MaNXB")] Sach sach, HttpPostedFileBase hinh) { if (ModelState.IsValid) { if (hinh != null) { var fileName = Path.GetFileName(hinh.FileName); sach.hinh = fileName; string path = Path.Combine(Server.MapPath("~/Hinh"), fileName); hinh.SaveAs(path); } db.Sach.Add(sach); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MaDM = new SelectList(db.DanhMuc, "MaDM", "TenDanhMuc", sach.MaDM); ViewBag.MaNXB = new SelectList(db.NhaXuatBan, "MaNXB", "TenNXB", sach.MaNXB); return(View(sach)); }
public bool ThemDichVu(dichvu dv) { CSDL db = new CSDL(); var query = db.dichvus.Where(p => p.madichvu == dv.madichvu).Count(); if (query == 0) { db.dichvus.Add(dv); db.SaveChanges(); return(true); } return(false); }
public ActionResult Edit(string address, string phone, string email) { var info = db.Info.SingleOrDefault(inf => inf.Id == 1); info.Address = address; info.Phone = phone; info.Email = email; db.Entry(info); db.SaveChanges(); return(Redirect("Index")); }
public bool ThemDichVuVaoHD(chitiethoadon cthd) { CSDL db = new CSDL(); var query = db.chitiethoadons.Where(p => p.mahoadon == cthd.mahoadon && p.madichvu == cthd.madichvu).Count(); if (query == 0) { db.chitiethoadons.Add(cthd); db.SaveChanges(); return(true); } return(false); }
public bool ThemHoaDonDV(hoadondichvu hd) { CSDL db = new CSDL(); var query = db.hoadondichvus.Where(p => p.mahoadon == hd.mahoadon).Count(); if (query == 0) { db.hoadondichvus.Add(hd); db.SaveChanges(); return(true); } return(false); }
public bool Add_NV(nhanvien nv) { try { CSDL db = new CSDL(); db.Entry(nv).State = System.Data.Entity.EntityState.Added; db.SaveChanges(); return(true); } catch (Exception e) { return(false); } }
public bool Themcanho(canho ch) { try { CSDL db = new CSDL(); db.canhoes.Add(ch); db.SaveChanges(); return(true); } catch (Exception e) { return(false); } }
public bool Xoacanho(int macanho) { try { CSDL db = new CSDL(); db.canhoes.Remove(db.canhoes.Find(macanho)); db.SaveChanges(); return(true); } catch (Exception e) { return(false); } }
public void AddorUpdate(hopdong a) { CSDL db = new CSDL(); if (db.hopdongs.Where(p => p.mahopdong.Equals(a.mahopdong)).Select(p => p).FirstOrDefault() != null) { var l1 = db.hopdongs.Where(p => p.mahopdong.Equals(a.mahopdong)).Select(p => p).FirstOrDefault(); l1.mahopdong = a.mahopdong; l1.maho = a.maho; l1.macanho = a.macanho; l1.giatien = a.giatien; l1.thoihan = a.thoihan; l1.manhanvien = a.manhanvien; l1.ngayki = a.ngayki; l1.dahuy = a.dahuy; l1.tenhopdong = a.tenhopdong; db.SaveChanges(); } else { db.hopdongs.Add(a); db.SaveChanges(); } }
public ActionResult SaveAccount(string name, string username, string password, string address, string phone) { if (db.Account.SingleOrDefault(acc => acc.UserName == username) != null) { // exists user return(RedirectToAction("")); } var newUser = new Account { Name = name, UserName = username, Password = password, Address = address, Phone = phone, IsAdmin = false }; db.Account.Add(newUser); db.SaveChanges(); Session["Account"] = newUser; return(RedirectToAction("Index", "Home")); }