public static bool EditUser(User model) { using (DeneysanContext db = new DeneysanContext()) { try { User record = db.User.Where(d => d.UserId == model.UserId).SingleOrDefault(); if (record != null) { record.FullName = model.FullName; record.Email = model.Email; if(model.Password != "") record.Password = model.Password; record.Institution = model.Institution; record.Contact = model.Contact; db.SaveChanges(); return true; } else return false; } catch (Exception) { return false; } } }
public static bool AddUsers(User record) { using (DeneysanContext db = new DeneysanContext()) { try { record.isActive = true; db.User.Add(record); db.SaveChanges(); return true; } catch (Exception) { return false; } } }
public ActionResult Edit(User model) { if (ModelState.IsValid) { if (RouteData.Values["id"] != null) { int nid = 0; bool isnumber = int.TryParse(RouteData.Values["id"].ToString(), out nid); if (isnumber) { model.UserId = nid; ViewBag.ProcessMessage = UserManager.EditUser(model); return View(model); } else { ViewBag.ProcessMessage = false; return View(model); } } else return View(); } else return View(); }
public static bool Record(string fullname, string email, string password, string institution, string contact) { try { using (DeneysanContext db = new DeneysanContext()) { User record = new User(); record.Email = email; record.FullName = fullname; record.Password = password; record.Institution = institution; record.Contact = contact; record.isActive = true; db.User.Add(record); db.SaveChanges(); return true; } } catch (Exception) { return false; } }
public ActionResult Add(User model) { ViewBag.ProcessMessage = UserManager.AddUsers(model); ModelState.Clear(); return View(); }