public ActionResult Create([Bind(Include = "MaTruong,MaNganh,KhoiThi,Diem1,Diem2,Diem3,NgayCapNhat")] TruongNganh truongnganh) { if (ModelState.IsValid) { TruongNganh findtruong = db.TruongNganhs.SingleOrDefault(t => t.MaTruong == truongnganh.MaTruong && t.MaNganh == truongnganh.MaNganh && t.KhoiThi == truongnganh.KhoiThi); truongnganh.NgayCapNhat = DateTime.Now; if (findtruong == null) { db.TruongNganhs.Add(truongnganh); } else { findtruong.NgayCapNhat = DateTime.Now; findtruong.Diem1 = truongnganh.Diem1; findtruong.Diem2 = truongnganh.Diem2; findtruong.Diem3 = truongnganh.Diem3; db.Entry(findtruong).State = EntityState.Modified; } db.SaveChanges(); SysLogEngine log = new SysLogEngine(); log.WriteUserLog("Tạo T-N, T-ID: " + findtruong.MaTruong + "N-ID: " + findtruong.MaNganh, User.Identity.GetUserId()); return(RedirectToAction("Details", "Truongs", new { ID = truongnganh.MaTruong })); } return(RedirectToAction("Details", "Truongs", new { ID = truongnganh.MaTruong })); }
public ActionResult Admin_ChangeStatePost(int ID, int stt) { //if (ID == null || stt == null) //{ // return HttpNotFound("NULL ID or STT"); //} if (stt < 0 || stt > 4) { return(HttpNotFound("Wrong status")); } BaiViet baiviet = db.BaiViets.SingleOrDefault(t => t.ID == ID); if (baiviet == null) { return(HttpNotFound("Bai Viet not found!")); } baiviet.Trangthai = stt; db.Entry(baiviet).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", "BaiViets")); }
public string Create([Bind(Include = "To,Mesage")] InternalMessage internalmessage) { if (ModelState.IsValid) { AspNetUser touser = db.AspNetUsers.SingleOrDefault(t => t.UserName == internalmessage.To); if (touser == null) { return("Wrong UserID or Username!"); } if (touser.Id == User.Identity.GetUserId()) { return("FAIL"); } internalmessage.To = touser.Id; internalmessage.From = User.Identity.GetUserId(); internalmessage.DateCreate = DateTime.Now; db.InternalMessages.Add(internalmessage); db.SaveChanges(); return("OK"); } ViewBag.From = new SelectList(db.AspNetUsers, "Id", "UserName", internalmessage.From); ViewBag.To = new SelectList(db.AspNetUsers, "Id", "UserName", internalmessage.To); return(null); }
public void RateBaiViet(int ID, int rate) { //if(ID == null || rate == null) //{ // return; //} string IDUser = User.Identity.GetUserId(); RatePost item = db.RatePosts.SingleOrDefault(t => t.IDBaiViet == ID && t.IDUsername == IDUser); // Neu nguoi post cap nhat if (item == null) { item = new RatePost(); item.IDUsername = IDUser; item.IDBaiViet = ID; item.Like = (rate == 1 ? true : false); db.RatePosts.Add(item); db.SaveChanges(); return; } else { item.Like = (rate == 1 ? true : false); db.Entry(item).State = EntityState.Modified; db.SaveChanges(); return; } }
public ActionResult AssignUserToRole(string Username, string IDRole) { AspNetUser user = db.AspNetUsers.SingleOrDefault(t => t.UserName == Username); AspNetRole role = db.AspNetRoles.SingleOrDefault(t => t.Id == IDRole); AccountController account = new AccountController(); account.UserManager.AddToRoleAsync(user.Id, role.Name); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "idMBTI,Tags,GioiThieu")] MBTI mBTI) { if (ModelState.IsValid) { db.MBTIs.Add(mBTI); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(mBTI)); }
public ActionResult Create([Bind(Include = "Ten,ID,MoTa")] ThanhPho thanhpho) { if (ModelState.IsValid) { db.ThanhPhoes.Add(thanhpho); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(thanhpho)); }
public ActionResult Create([Bind(Include = "id,Tieude,Noidung,userid,Tabs")] Question question) { if (ModelState.IsValid) { question.Ngaydang = DateTime.Now; question.userid = User.Identity.GetUserId(); db.Questions.Add(question); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.userid = new SelectList(db.AspNetUsers, "Id", "UserName", question.userid); return(View(question)); }
public ActionResult Create([Bind(Include = "Ten,MaNganh")] Nganh nganh) { if (ModelState.IsValid) { db.Nganhs.Add(nganh); db.SaveChanges(); SysLogEngine log = new SysLogEngine(); log.WriteUserLog("Tạo ngành: " + nganh.MaNganh, User.Identity.GetUserId()); return(RedirectToAction("Index")); } return(View(nganh)); }
public ActionResult Create([Bind(Include = "Ten,Website,IDThanhPho,MaTruong,LoaiTruong")] Truong truong) { if (ModelState.IsValid) { db.Truongs.Add(truong); db.SaveChanges(); SysLogEngine log = new SysLogEngine(); log.WriteUserLog("Tạo trường " + truong.MaTruong, User.Identity.GetUserId()); return(RedirectToAction("Details", new { id = truong.MaTruong })); } ViewBag.IDThanhPho = new SelectList(db.ThanhPhoes, "ID", "Ten", truong.IDThanhPho); return(View(truong)); }
public ActionResult tangsach(List <SachJSONRecieve> saches) { for (int i = 0; i < saches.Count; i++) { if (saches[i].id < 0) { Sach s = new Sach(); s.linkanh = saches[i].linkanh; s.NXB = saches[i].nxb; s.tacgia = saches[i].tacgia; s.Ten = saches[i].ten; addnewsachtodatabase(s); saches[i].id = s.id; } SachChoMuon cm = new SachChoMuon(); cm.id_sach = saches[i].id; cm.id_nguoidung = User.Identity.GetUserId(); cm.loai = saches[i].loai; cm.soluong = saches[i].soluong; db.SachChoMuons.Add(cm); } db.SaveChanges(); return(View()); }
public void SetValue(string key, int value) { SystemInformation info = db.SystemInformations.SingleOrDefault(t => t.Key == key); if (info == null) { info = new SystemInformation(); info.Key = key; info.value = value; db.SystemInformations.Add(info); db.SaveChanges(); } else { info.value = value; db.Entry(info).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } }
public void WriteLog(string Message) { ProjectHEntities db = new ProjectHEntities(); SystemLog log = new SystemLog(); log.DateCreated = DateTime.Now; log.LogMessage = Message; db.SystemLogs.Add(log); db.SaveChanges(); }
public void WriteUserLog(string Message, string userID) { ProjectHEntities db = new ProjectHEntities(); SystemLog log = new SystemLog(); log.DateCreated = DateTime.Now; Message += " Log by userid = " + userID;//User.Identity.GetUserId(); log.LogMessage = Message; db.SystemLogs.Add(log); db.SaveChanges(); }
public ActionResult GetFacebookUserInfor() { try { FacebookUserInfor fb = new ClassEngine.FacebookUserInfor(); var userId = User.Identity.GetUserId(); AspNetUser user = db.AspNetUsers.SingleOrDefault(t => t.Id == userId); FBUserInforReturn datauser = fb.getEmail(user.AspNetUserLogins.SingleOrDefault(t => t.LoginProvider == "Facebook").ProviderKey); user.profile_avatar_link = datauser.picture; user.hoTen = datauser.name; db.Entry(user).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } catch { ManageMessageId message = new ManageMessageId(); message = ManageMessageId.Error; return(RedirectToAction("Index", message)); } return(RedirectToAction("Index")); }