public ActionResult DatHang() { //Ki?m tra dang nh?p if (Session["GioHang"] == null) { RedirectToAction("Index", "Home"); } //Thêm don hàng DonHang ddh = new DonHang(); List <GioHang> gh = LayGioHang(); ddh.NgayDat = DateTime.Now; db.DonHangs.Add(ddh); db.SaveChanges(); //Thêm chi ti?t don hàng foreach (var item in gh) { ChiTietDonHang ctDH = new ChiTietDonHang(); ctDH.MaDonHang = ddh.MaDonHang; ctDH.MaSach = item.iMaSach; ctDH.SoLuong = item.iSoLuong; ctDH.DonGia = (decimal)item.dDonGia; db.ChiTietDonHangs.Add(ctDH); } db.SaveChanges(); return(View()); }
public ActionResult UpdateStatus(long?id, short?status) { Common.MessageComment message = new Common.MessageComment() { Status = false, Message = string.Empty }; if (IsLogin()) { if (ModelState.IsValid) { var tblComment = db.tblComments.Find(id); tblComment.Status = status ?? 0; db.Entry(tblComment).State = EntityState.Modified; message.Status = db.SaveChanges() > 0; message.Message = message.Status == true ? "Hành động thành công!" : "Hành động thất bại!"; } message.Message = "Hành động thất bại!"; } else { message.Message = "Bạn không có quền thực hiện hành động này!"; RedirectToAction("Login", "User"); } return(Json(message, JsonRequestBehavior.AllowGet)); }
public bool AddMenu(Menu menu) { try { var parentMenu = db.Menus.SingleOrDefault(x => x.ID == menu.ParentID); if (parentMenu == null || parentMenu.ID == menu.ID) { menu.Level = 1; menu.ParentID = null; } else { menu.Level = parentMenu.Level + 1; } db.Menus.Add(menu); db.SaveChanges(); return(true); } catch (Exception) { return(false); } }
public IActionResult AddUnit(AddUnitViewModel model) { if (ModelState.IsValid) { UnitModel newUnit = new UnitModel(); newUnit.ARM = model.ARM; newUnit.CMD = model.CMD; newUnit.DEF = model.DEF; newUnit.FA = model.FA; newUnit.MAT = model.MAT; newUnit.MaxUnit = model.MaxUnit; newUnit.MinUnit = model.MinUnit; newUnit.PointCost = model.PointCost; newUnit.RAT = model.RAT; newUnit.SPD = model.SPD; newUnit.STR = model.STR; context.Units.Add(newUnit); context.SaveChanges(); return(Redirect("/")); } return(View(model)); }
public ActionResult Create(HttpPostedFileBase fileUpload, [Bind(Include = "MaSach,TenSach,GiaBan,MoTa,AnhBia,NgayCapNhat,SoLuongTon,MaChuDe,MaNXB,Moi")] Sach sach) { //Kiểm tra đường dẫn ảnh bìa if (fileUpload == null) { ViewBag.ThongBao = "Chọn hình ảnh!"; return(View()); } if (ModelState.IsValid) { //Lưu tên file var fileName = Path.GetFileName(fileUpload.FileName); //Lưu đường dẫn của file var path = Path.Combine(Server.MapPath("~/HinhAnhSP"), fileName); //Kiểm tra hình ảnh đã tồn tại chưa if (System.IO.File.Exists(path)) { ViewBag.ThongBao = "Hình ảnh đã tồn tại"; } else { fileUpload.SaveAs(path); } sach.AnhBia = fileUpload.FileName; sach.NgayCapNhat = DateTime.Now; db.Saches.Add(sach); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MaChuDe = new SelectList(db.ChuDes, "MaChuDe", "TenChuDe", sach.MaChuDe); ViewBag.MaNXB = new SelectList(db.NhaXuatBans, "MaNXB", "TenNXB", sach.MaNXB); return(View(sach)); }
public ActionResult Create([Bind(Include = "IDDichBenh,TenDich,PhamVi,SoCaMac,TuVong,DaKhoi,NgCapNhap")] DichBenh dichBenh) { if (ModelState.IsValid) { db.DichBenhs.Add(dichBenh); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(dichBenh)); }
public ActionResult Create([Bind(Include = "id,name,phone,address,membership,email,created_at,username,password,status")] Customer customer) { if (ModelState.IsValid) { db.Customers.Add(customer); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(customer)); }
public ActionResult Create([Bind(Include = "MaNXB,TenNXB,DiaChi,DienThoai")] NhaXuatBan nhaXuatBan) { if (ModelState.IsValid) { db.NhaXuatBans.Add(nhaXuatBan); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(nhaXuatBan)); }
public ActionResult Create([Bind(Include = "IDKhoa,TenKhoa")] Khoa khoa) { if (ModelState.IsValid) { db.Khoas.Add(khoa); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(khoa)); }
public ActionResult Create([Bind(Include = "IDTinTuc,TieuDe,NoiDung,MoTa,img,NgayDang")] TinTuc tinTuc) { if (ModelState.IsValid) { db.TinTucs.Add(tinTuc); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tinTuc)); }
public ActionResult Create([Bind(Include = "id,code,name,slug,description,created_at")] Category category) { if (ModelState.IsValid) { db.Categories.Add(category); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public ActionResult Create([Bind(Include = "MaChuDe,TenChuDe")] ChuDe chuDe) { if (ModelState.IsValid) { db.ChuDes.Add(chuDe); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(chuDe)); }
public ActionResult Create([Bind(Include = "IDBenhNhan,HoTen,GioiTinh,NamSinh,Email,DienThoai,DiaChi,CMND,TaiKhoan,MatKhau,Role")] BenhNhan benhNhan) { if (ModelState.IsValid) { db.BenhNhans.Add(benhNhan); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(benhNhan)); }
public ActionResult Create([Bind(Include = "IDTrungTam,TenTrungTam,DiaChi,IDTinh")] TrungTamYTe trungTamYTe) { if (ModelState.IsValid) { db.TrungTamYTes.Add(trungTamYTe); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.IDTinh = new SelectList(db.Tinhs, "IDTinh", "TenTinh", trungTamYTe.IDTinh); return(View(trungTamYTe)); }
public ActionResult Create([Bind(Include = "IDBacsi,HoTen,Email,DienThoai,TaiKhoan,MatKhau,IDKhoa,Role")] Bacsi bacsi) { if (ModelState.IsValid) { db.Bacsis.Add(bacsi); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.IDKhoa = new SelectList(db.Khoas, "IDKhoa", "TenKhoa", bacsi.IDKhoa); return(View(bacsi)); }
public ActionResult Create([Bind(Include = "IDCauHoi,IDBenhNhan,CauHoi,TraLoi,NgayHoi")] HoiDap hoiDap) { if (ModelState.IsValid) { db.HoiDaps.Add(hoiDap); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.IDBenhNhan = new SelectList(db.BenhNhans, "IDBenhNhan", "HoTen", hoiDap.IDBenhNhan); return(View(hoiDap)); }
public ActionResult Create([Bind(Include = "IDThongBao,NoiDung,IDBenhNhan,NgThongBao")] ThongBao thongBao) { if (ModelState.IsValid) { db.ThongBaos.Add(thongBao); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.IDBenhNhan = new SelectList(db.BenhNhans, "IDBenhNhan", "HoTen", thongBao.IDBenhNhan); return(View(thongBao)); }
public ActionResult Create([Bind(Include = "IDHoSo,IDBenhNhan,IDBacSi,NgayKham,KetQua,GhiChu")] HoSo hoSo) { if (ModelState.IsValid) { db.HoSoes.Add(hoSo); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.IDBacSi = new SelectList(db.Bacsis, "IDBacsi", "HoTen", hoSo.IDBacSi); ViewBag.IDBenhNhan = new SelectList(db.BenhNhans, "IDBenhNhan", "HoTen", hoSo.IDBenhNhan); return(View(hoSo)); }
public ActionResult Create([Bind(Include = "id,code,customer_id,staff_id,address,phone,email,total_price,note,status,created_at")] Order order) { if (ModelState.IsValid) { db.Orders.Add(order); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.customer_id = new SelectList(db.Customers, "id", "name", order.customer_id); ViewBag.staff_id = new SelectList(db.Staffs, "id", "name", order.staff_id); return(View(order)); }
public ActionResult Create([Bind(Include = "IDLich,IDBenhNhan,IDBacSi,BatDau,KetThuc,GhiChu,TrangThai")] LichHen lichHen) { if (ModelState.IsValid) { db.LichHens.Add(lichHen); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.IDBacSi = new SelectList(db.Bacsis, "IDBacsi", "HoTen", lichHen.IDBacSi); ViewBag.IDBenhNhan = new SelectList(db.BenhNhans, "IDBenhNhan", "HoTen", lichHen.IDBenhNhan); return(View(lichHen)); }
public ActionResult ChangeUserInformation() { var usersession = (UserLogin)Session[Ban_Hang_Dien_Tu_CNWeb.Common.CommonConstants.USER_SESSION]; Customer customer = db.Customers.Find(usersession.UserID); ViewBag.Password = customer.password; ViewBag.Name = customer.name; ViewBag.Address = customer.address; ViewBag.Phone = customer.phone; ViewBag.Email = customer.email; string password = Request.Form["Password"].ToString(); string confirmpassword = Request.Form["ConfirmPassword"].ToString(); string name = Request.Form["NameUser"]; string address = Request.Form["Address"]; string phone = Request.Form["Phone"]; string email = Request.Form["Email"]; if (password == "" && confirmpassword == "") { customer.name = name; customer.address = address; customer.phone = phone; customer.email = email; ViewBag.Success = "Changed Successfully"; db.SaveChanges(); return(View()); } else if ((password != confirmpassword) || confirmpassword == "" || password == "") { MessageBox.Show("Please check your password and confirm your password"); return(View()); } else if (Common.Encryptor.MD5Hash(password) == customer.password) { MessageBox.Show("Your new password is similar as your old password "); return(View()); } else { customer.password = Common.Encryptor.MD5Hash(password); customer.name = name; customer.address = address; customer.phone = phone; customer.email = email; db.SaveChanges(); ViewBag.Success = "Changed Successfully"; return(View()); } }
// SIGNUP public bool User_Signup(BenhNhan entity) { try { entity.Role = 0; db.BenhNhans.Add(entity); db.SaveChanges(); return(true); } catch (Exception) { return(false); } }
public ActionResult Create(TINHTRANGSACH tINHTRANGSACH) { try { db.TINHTRANGSACHes.Add(tINHTRANGSACH); db.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public bool AddCompanyIn4(Information in4) { try { db.Information.Add(in4); db.SaveChanges(); return(true); } catch (Exception) { return(false); } }
public bool AddArticle(Article article) { try { article.CreateDate = DateTime.Now; db.Articles.Add(article); db.SaveChanges(); return(true); } catch (Exception) { return(false); } }
public IActionResult Put(int id, [FromBody] Employee emp) { try { using (ModelDbContext db = new ModelDbContext()) { var x = db.Employees.FirstOrDefault(x => x.ID == id); if (x == null) { return(NotFound()); } else { x.FirstName = emp.FirstName; x.LastName = emp.LastName; x.Gender = emp.Gender; x.Salary = emp.Salary; db.SaveChanges(); return(Ok()); } } } catch (Exception e) { throw e; } }
public IActionResult Delete(int id) { try { using (ModelDbContext db = new ModelDbContext()) { var x = db.Employees.FirstOrDefault(x => x.ID == id); if (x == null) { return(NotFound()); } else { db.Employees.Remove(x); db.SaveChanges(); return(Ok()); } } } catch (Exception ex) { throw ex; } }
public override void Delete(ModelDbContext context) { context.Warlocks.Remove(context.Warlocks.SingleOrDefault(c => c.ID == this.ID)); var soloAbils = (context.WarlockAbillities.Where(c => c.WarlockId == ID)); foreach (var abil in soloAbils) { context.WarlockAbillities.Remove(abil); } var soloSpells = (context.WarlockSpells.Where(c => c.WarlockId == ID)); foreach (var spell in soloSpells) { context.WarlockSpells.Remove(spell); } var soloWeaps = (context.WarlockWeapons.Where(c => c.WarlockId == ID)); foreach (var weap in soloWeaps) { context.WarlockWeapons.Remove(weap); } context.SaveChanges(); }
public bool InsertAndUpdate(tblUser user) { using (var db = new ModelDbContext()) { var item = new tblUser() { Id = user.Id }; if (db.tblUsers.Any(p => p.Id == user.Id)) { db.tblUsers.Attach(item); item.FullName = user.FullName; item.ModifyDate = DateTime.Now; item.UserName = user.UserName; item.Password = Commons.Encode.MD5(user.Password); item.Img = user.Img; item.ImgResizer = user.ImgResizer; item.Email = user.Email; } else { db.tblUsers.Add(user); } return(db.SaveChanges() > 0); } }
public ActionResult Update(string staffid, string percentage, string project, string memo) { if (!User.Identity.IsAuthenticated) { return(null); } if (staffid == null || staffid.IsEmpty() || percentage == null || percentage.IsEmpty() || project == null || project.IsEmpty() || memo == null || memo.IsEmpty() ) { return(null); } ModelDbContext mdb = new ModelDbContext(); IQueryable <Domain> workPercetages = mdb.Domains; int staff = int.Parse(staffid); Domain aim = (from workPercetage in workPercetages where workPercetage.StaffId == staff select workPercetage).First(); aim.Percentage = 100 > int.Parse(percentage) ? int.Parse(percentage) : 100; aim.Project = project; aim.Memo = memo; mdb.SaveChanges(); return(null); }