public ActionResult Registration([Bind(Exclude = "IsEmailVerified,ActivationCode")] Users user) { bool Status = false; string message = ""; if (ModelState.IsValid) { #region var isExist = IsEmailExist(user.Email); if (isExist) { ModelState.AddModelError("EmailExist", "Електронна пошта вже існує"); return(View(user)); } #endregion #region if (user.StatusID == "Працівник") { var isEmployerExist = IsEmployerExist(user.IDEmployer); if (!isEmployerExist) { ModelState.AddModelError("EmployerExist", "Такого керівника не існує"); return(View(user)); } } #endregion #region Generate Activation Code user.ActivationCode = Guid.NewGuid(); #endregion #region Password Hashing user.Password = Crypto.Hash(user.Password); user.ConfirmPassword = Crypto.Hash(user.ConfirmPassword); #endregion user.IsEmailVerified = false; #region Save to Database using (ScheduleEntities dc = new ScheduleEntities()) { dc.Users.Add(user); dc.SaveChanges(); SendVerificationLinkEmail(user.Email, user.ActivationCode.ToString()); message = "Реєстрація успішно виконана. Посилання для активації облікового запису " + " було надіслано на вашу електронну пошту: " + user.Email; Status = true; } #endregion } else { message = "Невірний запит"; } ViewBag.Message = message; ViewBag.Status = Status; return(View(user)); }
private void save_Button_Click(object sender, EventArgs e) { if (!IsNewCustomerValid()) { return; } using (ent = new ScheduleEntities()) {//adds new customer var newCustomer = new customer() { customerName = name_TextBox.Text, active = IsActive(), createDate = UserTracker.CurrentTime, createdBy = UserTracker.ActiveUser.userName, lastUpdate = UserTracker.CurrentTime, lastUpdateBy = UserTracker.ActiveUser.userName, addressId = selectedAddressID }; ent.customers.Add(newCustomer); ent.SaveChanges(); } AddCust_SaveClicked(this, e); this.Close(); }
public JsonResult SaveEvent(Events e) { var status = false; using (ScheduleEntities dc = new ScheduleEntities()) { var username = User.Identity.Name; var u = dc.Users.Where(t => t.Email == username).FirstOrDefault(); if (e.EventID > 0) { var v = dc.Events.Where(a => a.EventID == e.EventID).FirstOrDefault(); if (v != null) { v.Subject = e.Subject; v.Start = e.Start; v.End = e.End; v.Description = e.Description; v.IsFullDay = e.IsFullDay; v.ThemeColor = e.ThemeColor; v.UserID = u.UserID; } } else { e.UserID = u.UserID; dc.Events.Add(e); } dc.SaveChanges(); status = true; } return(new JsonResult { Data = new { status = status } }); }
//Update database record private void UpdateAppointment() { try { using (ent = new ScheduleEntities()) { var currentAppointment = ent.appointments.Attach(AppointmentIndex); currentAppointment.customerId = selectedCustomerID; currentAppointment.userId = ActiveUser.userId; currentAppointment.title = title_TextBox.Text; currentAppointment.location = location_TextBox.Text; currentAppointment.contact = contact_TextBox.Text; currentAppointment.type = type_TextBox.Text; currentAppointment.url = url_TextBox.Text; currentAppointment.description = description_TextBox.Text; currentAppointment.start = start_TimePicker.Value.ToUniversalTime(); currentAppointment.end = end_TimePicker.Value.ToUniversalTime(); currentAppointment.lastUpdate = CurrentTime; currentAppointment.lastUpdateBy = ActiveUser.userName; ent.SaveChanges(); } } catch (Exception) { throw; } }
////Country Controls private void addCountry_Button_Click(object sender, EventArgs e) { if (!IsNewCountryValid()) { return; } try { using (ent = new ScheduleEntities()) { var newCountry = new country { countryName = countryName_TextBox.Text, createDate = UserTracker.CurrentTime, createdBy = UserTracker.ActiveUser.userName, lastUpdate = UserTracker.CurrentTime, lastUpdateBy = UserTracker.ActiveUser.userName }; ent.countries.Add(newCountry); ent.SaveChanges(); PopulateCountryComboBox(); countryName_TextBox.Text = ""; MessageBox.Show($"'{newCountry.countryName}' was added", "New Country"); } } catch (Exception) { MessageBox.Show("Something went wrong", "Error"); } }
private void FillReport() { using (ent = new ScheduleEntities()) { var cuQuery = from cu in ent.customers orderby cu.customerName ascending select cu; foreach (var cu in cuQuery.ToList()) { //Lambdas allow for associated records from several different tables to be used together in this report var custAddress = ent.addresses.FirstOrDefault(a => a.addressId == cu.addressId); var custCity = ent.cities.FirstOrDefault(c => c.cityId == custAddress.cityId); var custCountry = ent.countries.FirstOrDefault(ctry => ctry.countryId == custCity.countryId); display_TextBox.AppendText($"------------------------------------------{NewLine}"); display_TextBox.AppendText($"ID: {cu.customerId} - Name: {cu.customerName}{NewLine}"); display_TextBox.AppendText($"------------------------------------------{NewLine}"); display_TextBox.AppendText($" Address: {custAddress.address1}{NewLine}"); display_TextBox.AppendText($" {custCity.cityName} - {custCountry.countryName}{NewLine}"); } } }
public bool IsEmailExist(string emailID) { using (ScheduleEntities dc = new ScheduleEntities()) { var v = dc.Users.Where(a => a.Email == emailID).FirstOrDefault(); return(v != null); } }
public bool IsEmployerExist(int?employerID) { using (ScheduleEntities dc = new ScheduleEntities()) { var v = dc.Users.Where(a => a.UserID == employerID).FirstOrDefault(); return(v != null); } }
//Show appointments based on calendar radio button selection private void CalendarRadioButtonSelection_Click(object sender, EventArgs e) { using (ent = new ScheduleEntities()) { PopulateAppointmentGrid(); DeselectRows(); } }
public void InitRepos() { var dbContext = new ScheduleEntities(); scheduleRepository = new Repository <Schedule>(dbContext); activityTypesRepository = new Repository <activity_type>(dbContext); activityClassRepository = new Repository <activity_class>(dbContext); }
public AddAppointment_Form() { InitializeComponent(); using (ent = new ScheduleEntities()) { PopulateCustomerComboBox(); } }
private void UpdateCustomer_Form_Load(object sender, EventArgs e) { using (ent = new ScheduleEntities()) { PopulateAddressComboBox(); } PopulateCustomerUpdateMenu(); }
//Schedule of each user private void FillReport() { using (ent = new ScheduleEntities()) { var userList = new List <string>(); var userQuery = from u in ent.users select u; foreach (var u in userQuery) { userList.Add($"{u.userId} - Username: {u.userName}"); } foreach (var u in userList) { display_TextBox.AppendText($"--------------------------------------------------"); display_TextBox.AppendText(Environment.NewLine); display_TextBox.AppendText($"ID: {u}"); display_TextBox.AppendText(Environment.NewLine); display_TextBox.AppendText($"--------------------------------------------------"); display_TextBox.AppendText(Environment.NewLine); foreach (var ap in userAppointments) { var uid = Convert.ToInt32(char.GetNumericValue(u.ToString().First())); if (uid == ap.userId) { if (ap.start.Kind == DateTimeKind.Unspecified || ap.start.Kind == DateTimeKind.Utc) { ap.start = DateTime.SpecifyKind(ap.start, DateTimeKind.Utc).ToLocalTime(); } if (ap.end.Kind == DateTimeKind.Unspecified || ap.end.Kind == DateTimeKind.Utc) { ap.end = DateTime.SpecifyKind(ap.end, DateTimeKind.Utc).ToLocalTime(); } display_TextBox.AppendText($" Title: {ap.title} - {ap.type}"); display_TextBox.AppendText(Environment.NewLine); display_TextBox.AppendText($" Scheduled for: {ap.start.ToString("MM/dd/yyyy")}"); display_TextBox.AppendText(Environment.NewLine); display_TextBox.AppendText($" From: {ap.start.ToString("hh:mm tt")} - To: {ap.end.ToString("hh:mm tt")} "); display_TextBox.AppendText(Environment.NewLine); display_TextBox.AppendText($" Description: {ap.description}"); display_TextBox.AppendText(Environment.NewLine); display_TextBox.AppendText(Environment.NewLine); } } } } }
public AddCustomer_Form() { InitializeComponent(); using (ent = new ScheduleEntities()) { PopulateAddressComboBox(); PopulateCityComboBox(); PopulateCountryComboBox(); } }
private void addAppointment_Form_SaveClicked(object sender, EventArgs e) { using (ent = new ScheduleEntities()) { PopulateAppointmentGrid(); appointments_DataGrid.DataSource = userAppointments; DeselectRows(); AppointmentIndex = null; } this.Enabled = true; }
private void updateCustomer_Form_SaveClicked(object sender, EventArgs e) { using (ent = new ScheduleEntities()) { PopulateCustomerGrid(); customer_DataGrid.DataSource = userCustomers; DeselectRows(); CustomerIndex = null; } this.Enabled = true; }
private void findAdvisorID() { using (ScheduleEntities dbcon = new ScheduleEntities()) { var advisorNameToId = (from adv in dbcon.AdvisorTables where adv.AdvisorUserName == userName select adv).First(); Session.Add("AdvID", 3); } }
private void findStudentID() { using (ScheduleEntities dbcon = new ScheduleEntities()) { var studentNameToId = (from stu in dbcon.StudentTables where stu.StudentUserName == userName select stu).First(); Session.Add("StdID", studentNameToId.StudentID); } }
public JsonResult GetEvents() { using (ScheduleEntities dc = new ScheduleEntities()) { var username = User.Identity.Name; var u = dc.Users.Where(a => a.Email == username).FirstOrDefault(); var events = dc.Events.Where(a => a.UserID == u.UserID).ToList(); return(new JsonResult { Data = events, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); } }
public ActionResult Login(UserLogin login, string ReturnUrl = "") { string message = ""; using (ScheduleEntities dc = new ScheduleEntities()) { var v = dc.Users.Where(a => a.Email == login.Email).FirstOrDefault(); if (v != null) { if (!v.IsEmailVerified) { ViewBag.Message = "Спершу підтвердьте свою електронну адресу"; return(View()); } if (string.Compare(Crypto.Hash(login.Password), v.Password) == 0) { int timeout = login.RememberMe ? 525600 : 20; var ticket = new FormsAuthenticationTicket(login.Email, login.RememberMe, timeout); string encrypted = FormsAuthentication.Encrypt(ticket); var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted); cookie.Expires = DateTime.Now.AddMinutes(timeout); cookie.HttpOnly = true; Response.Cookies.Add(cookie); if (Url.IsLocalUrl(ReturnUrl)) { return(Redirect(ReturnUrl)); } else { return(RedirectToAction("Index", "Home")); } } else { message = "Надано недійсні облікові дані"; } } else { message = "Надано недійсні облікові дані"; } } ViewBag.Message = message; return(View()); }
public JsonResult DeleteEvent(int eventID) { var status = false; using (ScheduleEntities dc = new ScheduleEntities()) { var v = dc.Events.Where(a => a.EventID == eventID).FirstOrDefault(); if (v != null) { dc.Events.Remove(v); dc.SaveChanges(); status = true; } } return(new JsonResult { Data = new { status = status } }); }
public UserMenu_Form() { InitializeComponent(); using (ent = new ScheduleEntities()) { PopulateUserMenu(); appointments_DataGrid.DataSource = userAppointments; appointments_DataGrid.Columns["customer"].Visible = false; appointments_DataGrid.Columns["user"].Visible = false; customer_DataGrid.DataSource = userCustomers; customer_DataGrid.Columns["address"].Visible = false; ShowReminder(); } }
//Show a reminder for appointments that will happen within 15 minutes private void ShowReminder() { using (ent = new ScheduleEntities()) { foreach (var appt in userAppointments) { //This lambda allows me to get the customer which corresponds with the current appointment in this foreach block var cust = ent.customers.FirstOrDefault(c => c.customerId == appt.customerId); var timeLeft = appt.start - CurrentTime; if (timeLeft.TotalMinutes <= 15 && timeLeft.TotalSeconds > 0) { MessageBox.Show($"You have an appointment with {cust.customerName} today at {appt.start.ToString("hh:mm tt")}", "Appointment Reminder"); } } } }
/* No longer needed * private void RefreshSession() * { * using (ScheduleEntities dbcon = new ScheduleEntities()) * { * * if (Session.Count > 0) * { * studentName = Session["User"].ToString(); * * var studentNameToId = * (from stu in dbcon.StudentTables * where stu.StudentUserName == studentName * select stu).First(); * * Session.Add("StdID", studentNameToId.StudentID); * * studentID = Convert.ToInt32(Session["StdID"].ToString()); * } * } * } */ //Add button protected void addBtn_Click(object sender, EventArgs e) { using (ScheduleEntities dbcon = new ScheduleEntities()) { var studentIDToAdvisorID = (from apt in dbcon.AppointmentTables where apt.StudentID == studentID select apt).First(); int advisorID = studentIDToAdvisorID.AdvisorID; var advisorDates = (from date in dbcon.AdvisorTables where date.AdvisorID == advisorID select date).First(); if (true /*Calendar1.SelectedDate.ToString() >= advisorDates.advisorStartDate && * Calendar1.SelectedDate.ToString() <= advisorDates.advisorEndDate*/) { AppointmentTable app = new AppointmentTable(); app.StudentID = studentID; app.AdvisorID = advisorID; app.AppointmentDate = Convert.ToDateTime(Calendar1.SelectedDate.ToString()); app.AppointmentTime = TimeSpan.Parse(TextBox2.Text); app.AppointmentReason = TextBox3.Text; // add data to the table dbcon.AppointmentTables.Add(app); dbcon.SaveChanges(); } else { } } // show data in the GridView GridView1.DataBind(); }
private void save_Button_Click(object sender, EventArgs e) { if (!IsValid()) { return; } using (ent = new ScheduleEntities()) { //update record in the table var currentRecord = ent.customers.Attach(CustomerIndex); currentRecord.customerName = name_TextBox.Text; currentRecord.addressId = selectedAddressID; currentRecord.active = IsActive(); currentRecord.lastUpdate = CurrentTime; currentRecord.lastUpdateBy = ActiveUser.userName; ent.SaveChanges(); } UpCust_SaveClicked(this, e); this.Close(); }
protected void Page_Load(object sender, EventArgs e) { Session.Clear(); Session.Add("User", "kabambora"); userName = Session["User"].ToString(); using (ScheduleEntities dbcon = new ScheduleEntities()) { var userToRole = (from x in dbcon.UserTables where x.UserName == userName select x.UserRole).First(); if (userToRole == "Student") { isStudent = true; var studentNameToId = (from stu in dbcon.StudentTables where stu.StudentUserName == userName select stu).First(); Session.Add("StdID", studentNameToId.StudentID); } else { isStudent = false; var advisorNameToId = (from adv in dbcon.AdvisorTables where adv.AdvisorUserName == userName select adv).First(); Session.Add("AdvID", advisorNameToId.AdvisorID); } } }
//public event EventHandler UserLoggedIn; private void AttemptLogin() { using (entity = new ScheduleEntities()) { var errorBox = new CustomMessageBox_Form(); var userQuery = from u in entity.users where u.userName == username_TextBox.Text select u; if (userQuery.Count() == 1) {//Check to see if selected User has correct password. var sUser = userQuery.First(); if (sUser.userName == username_TextBox.Text && sUser.password == password_TextBox.Text) {//Set this user as one to be tracked, then open up this user's account menu. UserTracker.GetUser(sUser); var userMenu = new UserMenu_Form(); userMenu.ExitClicked += new EventHandler(userMenu_Form_ExitClicked); userMenu.Show(); TrackLogins.SaveToLogFile(); this.Hide(); } else { errorBox.ShowMessage(CredentialsDontMatch, LoginFailed, OkButton); return; } } else { errorBox.ShowMessage(InvalidUsername, LoginFailed, OkButton); return; } } }
//Delete Button protected void Button1_Click(object sender, EventArgs e) { using (ScheduleEntities dbcon = new ScheduleEntities()) { if (GridView1.SelectedDataKey.Value != null) { // add data to the dbcon // select the row int item = Convert.ToInt32( GridView1.SelectedDataKey.Value.ToString()); AppointmentTable app = (from x in dbcon.AppointmentTables where x.AppointmentID == item select x).First(); //delete row from the table dbcon.AppointmentTables.Remove(app); dbcon.SaveChanges(); } } GridView1.DataBind(); }
public ActionResult VerifyAccount(string id) { bool Status = false; using (ScheduleEntities dc = new ScheduleEntities()) { dc.Configuration.ValidateOnSaveEnabled = false; var v = dc.Users.Where(a => a.ActivationCode == new Guid(id)).FirstOrDefault(); if (v != null) { v.IsEmailVerified = true; dc.SaveChanges(); Status = true; } else { ViewBag.Message = "Невірний запит"; } } ViewBag.Status = Status; return(View()); }
////Address Controls private void addAddress_Button_Click(object sender, EventArgs e) { if (!IsNewAddressValid()) { return; } try { using (ent = new ScheduleEntities()) { var newAddress = new address() { address1 = address1_TextBox.Text, address2 = address2_TextBox.Text, cityId = selectedCityID, postalCode = postal_TextBox.Text, phone = phone_TextBox.Text, createDate = UserTracker.CurrentTime, createdBy = UserTracker.ActiveUser.userName, lastUpdate = UserTracker.CurrentTime, lastUpdateBy = UserTracker.ActiveUser.userName }; ent.addresses.Add(newAddress); ent.SaveChanges(); PopulateAddressComboBox(); ClearAddressFields(); MessageBox.Show($"'{newAddress.address1}' was added", "New Address"); } } catch (Exception) { MessageBox.Show("Something went wrong", "Error"); } }