public HttpResponseMessage Post([FromBody] usersTable ut) { try { using (DataAccessLayer.ProjectMgrEntities entities = new DataAccessLayer.ProjectMgrEntities()) { if (ut.userid > 0) { entities.usersTables.Add(ut); entities.SaveChanges(); var message = Request.CreateResponse(HttpStatusCode.Created, ut); message.Headers.Location = new Uri(Request.RequestUri + "/" + ut.userid.ToString()); return(message); } else { var message = Request.CreateResponse(HttpStatusCode.LengthRequired); return(message); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
private void BtnDelet_Click(object sender, EventArgs e) { btnDesibel(); btnSave.Visible = false; try { string userna = dataGridViewX1.CurrentRow.Cells[0].Value.ToString(); if (RtlMessageBox.Show($"آیا از حذف {userna } مطمئن هستید ؟", "توجه", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.Yes) { NetCollegeEntities db = new NetCollegeEntities(); var user = dataGridViewX1.CurrentRow.Cells[0].Value.ToString(); usersTable usersTable = db.usersTables.Where(c => c.username == user).Single(); db.Entry(usersTable).State = System.Data.Entity.EntityState.Deleted; db.usersTables.Remove(usersTable); db.SaveChanges(); BindGrid(); } } catch (Exception) { RtlMessageBox.Show("خطا در انجام حذف!"); } btnEnebel(); }
public bool Post4Testing(int all) { usersTable ut = new usersTable(); ut.userid = 5; try { using (DataAccessLayer.ProjectMgrEntities entities = new DataAccessLayer.ProjectMgrEntities()) { if (ut.userid > 0) { entities.usersTables.Add(ut); entities.SaveChanges(); return(true); } else { return(false); } } } catch (Exception ex) { return(false); } }
public Profile DbUserToProfile(usersTable user) { Profile profile = new Profile(); profile.firstName = user.firstName; profile.lastName = user.lastName; profile.dateOfBirth = user.dateOfBirth.ToString(); profile.resident = user.resident; profile.privateId = user.privateId.ToString(); profile.gender = user.gender; profile.registrationDate = user.dateOfRegistration.ToString(); profile.registrationIp = user.registrationIp; profile.language = user.userLanguage; profile.mail = user.mail; profile.number = user.mobile.ToString(); profile.Password = user.userPassword; profile.address.country = user.country; profile.address.state = user.regionState; profile.address.city = user.city; profile.address.addressOne = user.addressOne; profile.address.addressTwo = user.addressTwo; profile.address.postalCode = user.postalCode; return(profile); }
public usersTable profileToDbUser(Profile profile) { usersTable user = new usersTable(); user.firstName = profile.firstName; user.lastName = profile.firstName; user.dateOfBirth = Convert.ToDateTime(profile.dateOfBirth); user.resident = profile.resident; user.privateId = Convert.ToInt64(profile.privateId); user.gender = profile.gender; user.dateOfRegistration = Convert.ToDateTime(profile.registrationDate); user.registrationIp = profile.registrationIp; user.userLanguage = profile.language; user.mail = profile.mail; user.mobile = Convert.ToInt64(profile.number); user.userPassword = ComputeSha256Hash(profile.Password); user.country = profile.address.country; user.regionState = profile.address.state; user.city = profile.address.city; user.addressOne = profile.address.addressOne; user.addressTwo = profile.address.addressTwo; user.postalCode = profile.address.postalCode; return(user); }
public ActionResult DeleteConfirmed(int id) { usersTable usersTable = db.usersTables.Find(id); db.usersTables.Remove(usersTable); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "userId,firstName,lastName,phoneNo,email,bookId")] usersTable usersTable) { if (ModelState.IsValid) { db.Entry(usersTable).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.bookId = new SelectList(db.bookTables, "bookId", "name", usersTable.bookId); return(View(usersTable)); }
public bool Put4Testing(int all) { usersTable ut = new usersTable(); ut.userid = 5; ut.firstname = "Testing1"; ut.lastname = "Testing1"; ut.employeeid = 0; try { using (DataAccessLayer.ProjectMgrEntities entities = new DataAccessLayer.ProjectMgrEntities()) { var entity = entities.usersTables.FirstOrDefault(u => u.userid == ut.userid); if (entity == null) { return(false); } else { if (ut.firstname != null) { entity.firstname = ut.firstname; } if (ut.lastname != null) { entity.lastname = ut.lastname; } if (ut.employeeid != null) { entity.employeeid = ut.employeeid; } if (ut.projectid != null) { entity.projectid = ut.projectid; } if (ut.taskid != null) { entity.taskid = ut.taskid; } entities.SaveChanges(); return(true); } } } catch (Exception ex) { return(false); } }
// GET: usersTables/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } usersTable usersTable = db.usersTables.Find(id); if (usersTable == null) { return(HttpNotFound()); } return(View(usersTable)); }
public HttpResponseMessage Post([FromBody] usersTable value) { var result = CtaxiDb.usersTable.FirstOrDefault(u => u.username == value.username && u.password == value.password); if (result != null) { FormsAuthentication.SetAuthCookie(value.username, false); return(ToJson(true)); } else { return(ToJson(false)); } }
// GET: usersTables/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } usersTable usersTable = db.usersTables.Find(id); if (usersTable == null) { return(HttpNotFound()); } ViewBag.bookId = new SelectList(db.bookTables, "bookId", "name", usersTable.bookId); return(View(usersTable)); }
//[HttpPut] //public HttpResponseMessage UpdateProjectId([FromBody]usersTable ut) //{ // try // { // using (DataAccessLayer.ProjectMgrEntities entities = new DataAccessLayer.ProjectMgrEntities()) // { // var entity = entities.usersTables.FirstOrDefault(u => u.userid == ut.userid); // if (entity == null) // { // return Request.CreateErrorResponse(HttpStatusCode.NotFound, "UserId = " + ut.userid + " not found to update."); // } // else // { // entity.projectid = ut.projectid; // entities.SaveChanges(); // return Request.CreateResponse(HttpStatusCode.OK, entity); // } // } // } // catch (Exception ex) // { // return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex); // } //} public HttpResponseMessage Put([FromBody] usersTable ut) { try { using (DataAccessLayer.ProjectMgrEntities entities = new DataAccessLayer.ProjectMgrEntities()) { var entity = entities.usersTables.FirstOrDefault(u => u.userid == ut.userid); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "UserId = " + ut.userid.ToString() + " not found to update.")); } else { if (ut.firstname != null) { entity.firstname = ut.firstname; } if (ut.lastname != null) { entity.lastname = ut.lastname; } if (ut.employeeid != null) { entity.employeeid = ut.employeeid; } if (ut.projectid != null) { entity.projectid = ut.projectid; } if (ut.taskid != null) { entity.taskid = ut.taskid; } entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, entity)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public void Add(Profile profile) { Validation valid = new Validation(profile); if (valid.IsValidAccount()) { ExchangeInfo DBUser = new ExchangeInfo(); usersTable user = DBUser.profileToDbUser(profile); entities.usersTables.Add(user); string path = System.IO.Directory.GetCurrentDirectory() + "\\ClientLog.txt"; using (StreamWriter writetext = new StreamWriter(path)) { writetext.WriteLine("new user " + profile.firstName + " has been registered"); } } }
public HttpResponseMessage PUT([FromBody] usersTable users) { try { using (shehryarTestingDBEntities entities = new shehryarTestingDBEntities()) { entities.usersTables.Add(users); entities.SaveChanges(); var message = Request.CreateResponse(HttpStatusCode.Created, users); message.Headers.Location = new Uri(Request.RequestUri + users.userID.ToString()); return(message); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
private void BtnSave_Click(object sender, EventArgs e) { NetCollegeEntities db = new NetCollegeEntities(); string password = encrypt(txtpass.Text); if (IsEdit == false) { usersTable usersTable = new usersTable() { username = txtuser.Text, password = password, uname = txtname.Text, ufamily = txtfamily.Text, accessType = comAcsses.SelectedIndex + 1 }; try { db.usersTables.Add(usersTable); RtlMessageBox.Show(" کاربر جدیداضافه شد "); db.SaveChanges(); } catch (DbUpdateException) { RtlMessageBox.Show("یوزر نیم تکراری است"); } catch { RtlMessageBox.Show("خطا در انجام عملیات"); } } btnAdd.Enabled = true; btnDelet.Enabled = true; btnEnebel(); BindGrid(); }