public ActionResult LoginCheck(LoginViewModel logInfos) { try { if (ModelState.IsValid) { // Move comparaison, and searching of person in an other layer PersonBAL balPerson = new PersonBAL(); Person personConnecting = balPerson.GetPersonByLogin(logInfos.Login, db); // Move comparaison in an other laver if (personConnecting != null && personConnecting.Password == HashService.GenerateSHA256String(logInfos.Password)) { Session["User"] = personConnecting; ViewBag.User = Session["User"]; return(RedirectToAction(nameof(HomeController.Index), "Home")); } else { Session["User"] = null; TempData["LoginError"] = "Invalid login or password"; return(RedirectToAction(nameof(AccountController.Login), "Account")); } } } catch (Exception) { ModelState.AddModelError("Error", "Error"); } Session["User"] = null; TempData["LoginError"] = "Invalid login or password"; return(RedirectToAction(nameof(AccountController.Login), "Account")); }
/// <summary> /// fires when Delete button is clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void DeleteRecord(object sender, GridViewDeleteEventArgs e) { int personID = Int32.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString()); // instantiate BAL PersonBAL pBAL = new PersonBAL(); Person person = new Person(); try { person.PersonID = personID; pBAL.Delete(person); lblMessage.Text = "Record Deleted Successfully."; } catch (Exception ee) { lblMessage.Text = ee.Message.ToString(); } finally { person = null; pBAL = null; } GridView1.EditIndex = -1; // Refresh the list BindGrid(); }
public HttpResponseMessage CreatePerson(PersonModel person) { int id = 0; PersonBAL BAL = new PersonBAL(); id = BAL.SavePerson(person); return(new HttpResponseMessage(HttpStatusCode.Created) { Content = new ObjectContent <int>(id, new XmlMediaTypeFormatter(), new MediaTypeWithQualityHeaderValue("application/xml")) }); }
public IHttpActionResult GetPerson(int id) { PersonBAL BAL = new PersonBAL(); PersonModel p = BAL.GetPersonDetail(id); return(Ok(p)); //return new HttpResponseMessage(HttpStatusCode.OK) //{ // Content = new ObjectContent<Person>(p, new XmlMediaTypeFormatter(), new MediaTypeWithQualityHeaderValue("application/xml")) //}; }
public IActionResult Index() { PersonBAL BAL = new PersonBAL(); var details = BAL.ReadPerson(); IList <Person> list = new List <Person>(); foreach (DataRow row in details.Tables[0].Rows) { Person person = new Person() { PersonID = int.Parse(row["PersonId"].ToString()), FirstName = row["FirstName"].ToString(), LastName = row["LastName"].ToString(), Email = row["Email"].ToString(), Mobile = long.Parse(row["Mobile"].ToString()) }; list.Add(person); } return(View(list)); }
/// <summary> /// Get GridView DataSource /// </summary> private DataTable GridDataSource() { PersonBAL p = new PersonBAL(); DataTable dTable = new DataTable(); try { dTable = p.Load(); } catch (Exception ee) { lblMessage.Text = ee.Message.ToString(); } finally { p = null; } return(dTable); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Label3.Text = Session[0].ToString(); List <Broker> brokers = BrokerBAL.GetBrokers(); List <Person> persons = PersonBAL.GetPersons(); List <Stock> stockes = StockBAL.GetTwoStock(); List <Order> orders = OrderBAL.GetAllOrders(); grd_view.Visible = true; DataTable dt = new DataTable(); //dt.Columns.Add("Quantity", typeof(int)); grd_view.DataSource = orders; grd_view.DataBind(); grd_view2.DataSource = stockes; grd_view2.DataBind(); grd_view3.DataSource = persons; grd_view3.DataBind(); grd_view4.DataSource = brokers; grd_view4.DataBind(); } }
public ActionResult Add(PersonRegisterViewModel newAccount) { try { if (ModelState.IsValid) { PersonBAL balPerson = new PersonBAL(); if (balPerson.IsLoginValid(newAccount.Login, db)) { if (newAccount.Roles == EnumRoles.Student) { StudentBAL balStudent = new StudentBAL(); balStudent.CreateStudentRegistering(newAccount, db); } else { InstructorBAL balInstructor = new InstructorBAL(); balInstructor.CreateInstructorRegistering(newAccount, db); } // Move searching of person in an other layer // getPersonByLogin(newAccount.Login) Session["User"] = balPerson.GetPersonByLogin(newAccount.Login, db); return(RedirectToAction(nameof(HomeController.Index), "Home")); } else { TempData["LoginError"] = "This login already exists"; return(RedirectToAction(nameof(AccountController.Register), "Account")); } } } catch (Exception) { ModelState.AddModelError("Error", "Error"); } return(RedirectToAction(nameof(HomeController.Index), "Home")); }
/// <summary> /// Add records into database /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void AddRecords(object sender, EventArgs e) { //Lets validate the page first if (!Page.IsValid) return; int intResult = 0; // Page is valid, lets go ahead and insert records // Instantiate BAL object PersonBAL pBAL = new PersonBAL(); // Instantiate the object we have to deal with Person person = new Person(); // set the properties of the object person.FirstName = txtFirstName.Text; person.LastName = txtLastName.Text; person.Age = Int32.Parse(txtAge.Text); try { intResult = pBAL.Insert(person); if (intResult > 0) lblMessage.Text = "New record inserted successfully."; else lblMessage.Text = "FirstName [<b>"+ txtFirstName.Text +"</b>] alredy exists, try another name"; } catch (Exception ee) { lblMessage.Text = ee.Message.ToString(); } finally { person = null; pBAL = null; } }
/// <summary> /// Get GridView DataSource /// </summary> private DataTable GridDataSource() { PersonBAL p = new PersonBAL(); DataTable dTable = new DataTable(); try { dTable = p.Load(); } catch (Exception ee) { lblMessage.Text = ee.Message.ToString(); } finally { p = null; } return dTable; }
/// <summary> /// Fires when Update button is clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void UpdateRecord(object sender, GridViewUpdateEventArgs e) { int personID = Int32.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString()); int intResult = 0; GridViewRow row = GridView1.Rows[e.RowIndex]; TextBox tFN = (TextBox) row.FindControl("txtFName"); TextBox tLN = (TextBox)row.FindControl("txtLName"); TextBox tAge = (TextBox)row.FindControl("txtAge"); // instantiate BAL PersonBAL pBAL = new PersonBAL(); Person person = new Person(); try { person.PersonID = personID; person.FirstName = tFN.Text; person.LastName = tLN.Text; person.Age = Int32.Parse(tAge.Text); intResult = pBAL.Update(person); if (intResult > 0) lblMessage.Text = "Record Updated Successfully."; else lblMessage.Text = "Record couldn't updated"; } catch (Exception ee) { lblMessage.Text = ee.Message.ToString(); } finally { person = null; pBAL = null; } GridView1.EditIndex = -1; // Refresh the list BindGrid(); }