public static dynamic GetUserWithTypeFromPassword(UserAccount userAccount, string password) { if (userAccount.Password == password) { using (var dbContext = new InventoryContext()) { if (userAccount.IsAdmin) { AdminAccount user = (from admin in dbContext.UserAccounts.OfType <AdminAccount>() where admin.Username == userAccount.Username select admin).First(); return(user); } else { StaffAccount user = (from staff in dbContext.UserAccounts.OfType <StaffAccount>() where staff.Username == userAccount.Username select staff).First(); return(user); } } } else { return(null); } }
public void ChoosingSelectedStaff(string email) { using (var db = new TT_ProjectContext()) { SelectedStaff = db.StaffAccounts.Where(e => e.Email.Trim() == email.Trim()).FirstOrDefault(); } }
static void Main(string[] args) { //Type: Personal; Plan: Basic AccountDetail accountDetail = new PersonalAccount(); accountDetail.Account = new BasicAccount(); accountDetail.LoadData(); //Type: Personal; Plan: Premium accountDetail.Account = new PremiumAccount(); accountDetail.LoadData(); //Type: Corporate; Plan: Basic accountDetail = new CorporateAccount(); accountDetail.Account = new BasicAccount(); accountDetail.LoadData(); //Type: Corporate; Plan: Premium accountDetail.Account = new PremiumAccount(); accountDetail.LoadData(); //Type: Staff; Plan: Basic accountDetail = new StaffAccount(); accountDetail.Account = new BasicAccount(); accountDetail.LoadData(); //Type: Staff; Plan: Premium accountDetail.Account = new PremiumAccount(); accountDetail.LoadData(); }
static void CreateNewStaffAccountUsingUserAccount() { //Create new account string username = "******"; string password = UserAccount.stringToHashString("testStaffUser"); bool isAnalyticsAllowed = true; bool isEditTablesAllowed = true; bool isAddDeliveryAllowed = true; UserAccount staff = StaffAccount.GetNewStaffAccount(username, password, isAnalyticsAllowed, isEditTablesAllowed, isAddDeliveryAllowed); //Commit to db using (var dbContext = new InventoryContext()) { try { dbContext.UserAccounts.Add(staff); dbContext.SaveChanges(); //Did work Console.WriteLine("It worked"); } catch (Exception ex) { //Didn't work Console.WriteLine(ex.ToString()); } } }
public StatusBarControl(IGlobalContext gContext) { _staffAccount = RightNowConnectService.GetService().GetAccountDetails(); InitializeComponent(_staffAccount); _gContext = gContext; }
public async Task <IActionResult> Edit(int id, [Bind("Id,StaffID,Name,PermissionID")] StaffAccount staffAccount) { if (id != staffAccount.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(staffAccount); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StaffAccountExists(staffAccount.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["PermissionID"] = new SelectList(_context.Permissions, "Id", "Name", staffAccount.PermissionID); return(View(staffAccount)); }
public bool IsCorrectLoginInfo(StaffAccount loginAccount) { Table <DAL.StaffAccount> staffAccountTable = GetStaffAccountTable(); var matchedRes = (from account in staffAccountTable where account.username == loginAccount.Username && account.password == loginAccount.Password select account).FirstOrDefault(); return(matchedRes != null); }
static UserAccount GetNewAccount(string username, string password, bool isAdmin, bool isAnalyticsAllowed, bool isEditTablesAllowed, bool isAddDeliveryAllowed) { if (isAdmin) { return(AdminAccount.CreateNewAdminAccount(username, password)); } else { return(StaffAccount.GetNewStaffAccount(username, password, isAnalyticsAllowed, isEditTablesAllowed, isAddDeliveryAllowed)); } }
/// <summary> /// Populates value of control on intialization of the control /// </summary> /// <param name="staffAccount"></param> public void PopulateControls(StaffAccount staffAccount) { logger.Debug("OutOfOfficeControl - PopulateControls() - Entry"); var OutOfOfficeViewModel = new OutOfOfficeViewModel(staffAccount); DataContext = OutOfOfficeViewModel; _staffAccount = staffAccount; logger.Debug("OutOfOfficeControl - PopulateControls() - Exit"); }
public void UpdateStaff(string email, string firstname, string lastname) { using (var db = new TT_ProjectContext()) { SelectedStaff = db.StaffAccounts.Where(c => c.Email == email).FirstOrDefault(); SelectedStaff.FirstName = firstname; SelectedStaff.LastName = lastname; db.SaveChanges(); } }
public async Task <IActionResult> Create([Bind("Id,StaffID,Name,PermissionID")] StaffAccount staffAccount) { if (ModelState.IsValid) { _context.Add(staffAccount); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["PermissionID"] = new SelectList(_context.Permissions, "Id", "Name", staffAccount.PermissionID); return(View(staffAccount)); }
public OutOfOfficeViewModel(StaffAccount staffAccount) { _staffAccount = staffAccount; OutOfOfficeFlag = _staffAccount.OooFlag; FromDateTime = _staffAccount.OooStart; ToDateTime = _staffAccount.OooEnd; PersonalMsgOption = _staffAccount.OooMsgOption; PersonalMsg = _staffAccount.OooMsg; ToTime = String.Format(Common.HourMinuteFormat, _staffAccount.OooEnd); FromTime = String.Format(Common.HourMinuteFormat, _staffAccount.OooStart); Timezone = _staffAccount.OooTimezone; }
internal string AddOrUpdateAccount(string staffID, string username, string password) { Table <DAL.StaffAccount> accTable = GetStaffAccountTable(); var matchedRes = (from acc in accTable where acc.staffID == staffID select acc).FirstOrDefault(); if (matchedRes == null) { StaffAccount temp = new StaffAccount(username, password); DAL.StaffAccount newData = new DAL.StaffAccount(); try { newData.staffID = staffID; newData.username = temp.Username; newData.password = temp.Password; accTable.InsertOnSubmit(newData); accTable.Context.SubmitChanges(); } catch (Exception ex) { return(ex.Message); } } else if (matchedRes != null) { if (password != "") { // Get encrypted password StaffAccount temp = new StaffAccount(username, password); password = temp.Password; } try { matchedRes.username = username; if (password != "") { matchedRes.password = password; } db.SubmitChanges(); } catch (Exception ex) { return(ex.Message); } } return(""); }
public ActionResult Add(StaffAccount staff) { if (ModelState.IsValid) { //encrypt password staff.Password = Password.Encrypt(staff.Password); _db.StaffAccounts.Add(staff); _db.SaveChanges(); TempData["message"] = $"Add Staff successfully!"; return(RedirectToAction("Index", new { key = staff.Username })); } return(View()); }
public void Handle(bool message) { StaffAccount staff = new StaffAccount() { Id = "02", Name = "Minh Tan", UserName = "******", Password = "******", Email = "*****@*****.**", Position = "Quản lí", Image = @"pack://application:,,,/BookStoreManagement;component/Resources/Img/4.png" }; _eventAggregator.PublishOnUIThread(staff); }
public void CreateStaffAccount(string email, string password, string firstname, string lastname) { using (var db = new TT_ProjectContext()) { var newStaffAccount = new StaffAccount { Email = email.Trim(), Passwrd = password.Trim(), FirstName = firstname.Trim(), LastName = lastname.Trim() }; db.StaffAccounts.Add(newStaffAccount); db.SaveChanges(); } }
/// <summary> /// Initializes and displays out of office dialog. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void statusButton_Click(object sender, EventArgs e) { _staffAccount = RightNowConnectService.GetService().GetAccountDetails(); if (_staffAccount != null) { var OOOControl = new OutOfOfficeControl(this); OOOControl.PopulateControls(_staffAccount); Window window = new Window { Title = Common.Title, Content = OOOControl, SizeToContent = SizeToContent.WidthAndHeight, WindowStartupLocation = WindowStartupLocation.CenterScreen, ResizeMode = ResizeMode.NoResize }; window.ShowDialog(); } }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent(StaffAccount staffAccount) { //this.components = new System.ComponentModel.Container(); this.statusButton = new System.Windows.Forms.Button(); //this.OutOfOfficeToolTip = new System.Windows.Forms.ToolTip(this.components); this.SuspendLayout(); // // statusButton // this.statusButton.BackColor = System.Drawing.Color.White; this.statusButton.Location = new System.Drawing.Point(0, -1); this.statusButton.Margin = new System.Windows.Forms.Padding(3, 3, 0, 3); this.statusButton.Name = "statusButton"; this.statusButton.Size = new System.Drawing.Size(162, 23); this.statusButton.TabIndex = 0; if (staffAccount.OooFlag) { this.statusButton.Text = "Out of Office"; this.statusButton.ForeColor = System.Drawing.Color.DarkRed; } else { this.statusButton.Text = "Available"; this.statusButton.ForeColor = System.Drawing.Color.DarkGreen; } this.statusButton.UseVisualStyleBackColor = false; this.statusButton.Click += new System.EventHandler(this.statusButton_Click); // // StatusBarControl // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.Transparent; this.Controls.Add(this.statusButton); this.Name = "StatusBarControl"; this.Size = new System.Drawing.Size(162, 28); this.ResumeLayout(false); }
public ActionResult Edit(StaffAccount staffAccount) { if (ModelState.IsValid || String.IsNullOrEmpty(staffAccount.Password)) { //dont update password if (String.IsNullOrEmpty(staffAccount.Password)) { var oldPassword = (from a in _db.StaffAccounts where a.ID == staffAccount.ID select a.Password).FirstOrDefault(); staffAccount.Password = oldPassword; } else { //update password staffAccount.Password = Password.Encrypt(staffAccount.Password); } _db.Entry(staffAccount).State = EntityState.Modified; _db.SaveChanges(); TempData["message"] = $"Update Staff Account successfully!"; return(RedirectToAction("Index", new { key = staffAccount.Username })); } return(View(staffAccount)); }
private void SignIn() { StaffAccount account = new StaffAccount(bunifuCustomTextbox_Username.Text, bunifuCustomTextbox_Password.Text); ThreadManager.DisplayLoadingScreen(); bool correctInfo = accManager.IsCorrectLoginInfo(account); if (correctInfo) { Form CallMainActive = new MainActive(accManager.GetStaffID(account.Username)); this.Hide(); CallMainActive.ShowDialog(); if (CallMainActive.DialogResult == DialogResult.OK) { this.bunifuCustomTextbox_Password.Text = ""; this.Show(); this.bunifuCustomTextbox_Username.Focus(); } } else { ErrorManager.MessageDisplay("Incorrect data", "", "Wrong username or passsword."); } }
/// <summary> /// Saves date on OK button click /// </summary> /// <param name="sender"></param> /// <param name="routedEventArgs"></param> public void OkClick(object sender, RoutedEventArgs routedEventArgs) { logger.Debug("OutOfOfficeControl - OkClick() - Entry"); var updatedAccount = new StaffAccount(); updatedAccount.OooFlag = OutOfOfficeCheckbox.IsChecked.GetValueOrDefault(); updatedAccount.OooTimezone = (TimezoneDropdown.SelectedValue != null) ? TimezoneDropdown.SelectedValue.ToString() : null; DateTime?fromDateTime = null; DateTime?toDateTime = null; if (FromDateTime.SelectedDate != null || ToDateTime.SelectedDate != null) { //Combining date and time to store string fromDate = FromDateTime.SelectedDate.GetValueOrDefault().Date.ToString("d"); string fromTime = FromTimeDropdown.SelectedValue.ToString(); string toDate = ToDateTime.SelectedDate.GetValueOrDefault().Date.ToString("d"); string toTime = ToTimeDropdown.SelectedValue.ToString(); fromDateTime = Convert.ToDateTime(fromDate + " " + fromTime); toDateTime = Convert.ToDateTime(toDate + " " + toTime); //Validating if user entered date/time without timezone. if ((fromDateTime != default(DateTime) || toDateTime != default(DateTime)) && TimezoneDropdown.SelectedValue == null) { System.Windows.Forms.MessageBox.Show(OOOExceptionMessages.TimezoneCannotBeEmpty, Common.ErrorLabel, MessageBoxButtons.OK, MessageBoxIcon.Error); TimezoneLabel.Content = "*" + Common.TimezoneLabel; TimezoneLabel.Foreground = new SolidColorBrush(Colors.Red); return; } //Validating if user entered From Date/Time is less than To Date/Time. if (fromDateTime > toDateTime) { System.Windows.Forms.MessageBox.Show(OOOExceptionMessages.FromDateGreaterThanToDate, Common.ErrorLabel, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (updatedAccount.OooTimezone != null) { string windowsTimezone = TimezoneService.GetService().GetWindowsTimezone(updatedAccount.OooTimezone); TimeZoneInfo timeszone = TimeZoneInfo.FindSystemTimeZoneById(windowsTimezone); fromDateTime = TimeZoneInfo.ConvertTimeToUtc((DateTime)fromDateTime, timeszone); toDateTime = TimeZoneInfo.ConvertTimeToUtc((DateTime)toDateTime, timeszone); } } updatedAccount.OooStart = fromDateTime; updatedAccount.OooEnd = toDateTime; updatedAccount.OooMsgOption = PersonalMsgOptionsDropdown.SelectedValue.ToString(); updatedAccount.OooMsg = PersonalMsgOptionsDropdown.SelectedValue.ToString().Equals(PersonalMsgOptions.StandardMessage) ? " " : PersonalMsgTextbox.Text; var result = RightNowConnectService.GetService().updateCustomFields(updatedAccount); if (result) { _statusBarControl.statusButton.Text = (updatedAccount.OooFlag) ? Common.OutOfOfficeLabel : Common.AvailableLabel; _statusBarControl.statusButton.ForeColor = (updatedAccount.OooFlag) ? Color.DarkRed : Color.DarkGreen; } Window.GetWindow(this).Close(); logger.Debug("OutOfOfficeControl - OkClick() - Exit"); }
/// <summary> /// Return Account's custom fields /// </summary> /// <returns></returns> public StaffAccount GetAccountDetails() { try { Debug("RightNowConnectService - GetAccountDetails() - Entry"); int accountId = OutOfOfficeClientAddIn.GlobalContext.AccountId; string query = String.Format(RightNowQueries.GetAccountDetailsQuery, accountId); string[] data = GetRNData(OracleRightNowOOOAddInNames.OutOfOfficeAddIn, query); string[] accountdetails = data[0].Split('|'); var staffAccount = new StaffAccount(); staffAccount.AccountId = accountId; //Fetching timezone string windowsTimezone = null; TimeZoneInfo timeszone = null; if (!string.IsNullOrEmpty(accountdetails[5])) { staffAccount.OooTimezone = accountdetails[5]; windowsTimezone = TimezoneService.GetService().GetWindowsTimezone(accountdetails[5]); timeszone = TimeZoneInfo.FindSystemTimeZoneById(windowsTimezone); } if (!string.IsNullOrEmpty(accountdetails[0])) { //staffAccount.OooStart = TimeZoneInfo.ConvertTime(XmlConvert.ToDateTime(accountdetails[0]), timeszone); DateTime dateTime = XmlConvert.ToDateTime(accountdetails[0], XmlDateTimeSerializationMode.Utc); staffAccount.OooStart = OutOfOfficeClientAddIn.GlobalContext.GetTimeZoneDateTime(staffAccount.OooTimezone, dateTime) ?? DateTime.Now; } else { staffAccount.OooStart = DateTime.Now; } if (!string.IsNullOrEmpty(accountdetails[1])) { //staffAccount.OooEnd = TimeZoneInfo.ConvertTime(XmlConvert.ToDateTime(accountdetails[1]), timeszone); DateTime dateTime = XmlConvert.ToDateTime(accountdetails[1], XmlDateTimeSerializationMode.Utc); staffAccount.OooEnd = OutOfOfficeClientAddIn.GlobalContext.GetTimeZoneDateTime(staffAccount.OooTimezone, dateTime) ?? DateTime.Now; } else { staffAccount.OooEnd = DateTime.Now; } if (!string.IsNullOrEmpty(accountdetails[2])) { staffAccount.OooFlag = (accountdetails[2].Equals("1")) ? true : false; } if (!string.IsNullOrEmpty(accountdetails[3])) { staffAccount.OooMsg = accountdetails[3]; } if (!string.IsNullOrEmpty(accountdetails[4])) { staffAccount.OooMsgOption = accountdetails[4]; } return(staffAccount); } catch (Exception e) { MessageBox.Show(OOOExceptionMessages.UnexpectedError, Common.Common.ErrorLabel, MessageBoxButtons.OK, MessageBoxIcon.Error); Error(e.Message, e.StackTrace); } Debug("RightNowConnectService - GetAccountDetails() - Exit"); return(null); }
/// <summary> /// Updates the latest values of the custome fields into database. /// </summary> /// <param name="staffAccount"></param> /// <returns></returns> public bool updateCustomFields(StaffAccount staffAccount) { try { Debug("RightNowConnectService - updateCustomFields() - Entry"); GenericField csFldOOOEnd = null; GenericField csFldOOOStart = null; Account account = new Account(); ID accountID = new ID(); accountID.id = OutOfOfficeClientAddIn.GlobalContext.AccountId; accountID.idSpecified = true; account.ID = accountID; // Out of Office Flag DataValue dv = new DataValue(); dv.Items = new Object[] { staffAccount.OooFlag }; dv.ItemsElementName = new ItemsChoiceType[] { ItemsChoiceType.BooleanValue }; GenericField csFldOOOFlag = new GenericField(); csFldOOOFlag.name = CustomField.OooFlag; csFldOOOFlag.dataType = DataTypeEnum.BOOLEAN; csFldOOOFlag.dataTypeSpecified = true; csFldOOOFlag.DataValue = dv; // Out of Office Start csFldOOOStart = new GenericField(); csFldOOOStart.name = CustomField.OooStart; csFldOOOStart.dataType = DataTypeEnum.DATETIME; csFldOOOStart.dataTypeSpecified = true; DataValue dvOooStart = null; if (staffAccount.OooStart != null && staffAccount.OooStart != default(DateTime)) { dvOooStart = new DataValue(); dvOooStart.Items = new Object[] { staffAccount.OooStart }; dvOooStart.ItemsElementName = new ItemsChoiceType[] { ItemsChoiceType.DateTimeValue }; } csFldOOOStart.DataValue = dvOooStart; // Out of Office End csFldOOOEnd = new GenericField(); csFldOOOEnd.name = CustomField.OooEnd; csFldOOOEnd.dataType = DataTypeEnum.DATETIME; csFldOOOEnd.dataTypeSpecified = true; DataValue dvOooEnd = null; if (staffAccount.OooEnd != null) { dvOooEnd = new DataValue(); dvOooEnd.Items = new Object[] { staffAccount.OooEnd }; dvOooEnd.ItemsElementName = new ItemsChoiceType[] { ItemsChoiceType.DateTimeValue }; } csFldOOOEnd.DataValue = dvOooEnd; // Out of Office Message Option DataValue dvOooMsgOption = new DataValue(); dvOooMsgOption.Items = new Object[] { staffAccount.OooMsgOption }; dvOooMsgOption.ItemsElementName = new ItemsChoiceType[] { ItemsChoiceType.StringValue }; GenericField csFldOOOMsgOption = new GenericField(); csFldOOOMsgOption.name = CustomField.OooMsgOption; csFldOOOMsgOption.dataType = DataTypeEnum.STRING; csFldOOOMsgOption.dataTypeSpecified = true; csFldOOOMsgOption.DataValue = dvOooMsgOption; // Out of Office Message DataValue dvOooMsg = new DataValue(); dvOooMsg.Items = new Object[] { staffAccount.OooMsg }; dvOooMsg.ItemsElementName = new ItemsChoiceType[] { ItemsChoiceType.StringValue }; GenericField csFldOOOMsg = new GenericField(); csFldOOOMsg.name = CustomField.OooMsg; csFldOOOMsg.dataType = DataTypeEnum.STRING; csFldOOOMsg.dataTypeSpecified = true; csFldOOOMsg.DataValue = dvOooMsg; // Out of Office Timezone GenericField csFldOOOTimezone = new GenericField(); csFldOOOTimezone.name = CustomField.OooTimezone; csFldOOOTimezone.dataType = DataTypeEnum.STRING; csFldOOOTimezone.dataTypeSpecified = true; DataValue dvOooTimezone = null; if (null != staffAccount.OooTimezone) { dvOooTimezone = new DataValue(); dvOooTimezone.Items = new Object[] { staffAccount.OooTimezone }; dvOooTimezone.ItemsElementName = new ItemsChoiceType[] { ItemsChoiceType.StringValue }; } csFldOOOTimezone.DataValue = dvOooTimezone; GenericObject customFieldsc = new GenericObject(); customFieldsc.GenericFields = new GenericField[] { csFldOOOFlag, csFldOOOStart, csFldOOOEnd, csFldOOOMsgOption, csFldOOOMsg, csFldOOOTimezone }; customFieldsc.ObjectType = new RNObjectType() { TypeName = CustomField.AccountCustomFieldCollectionTypeName }; GenericField customFieldsPackage = new GenericField(); customFieldsPackage.name = "c"; customFieldsPackage.dataType = DataTypeEnum.OBJECT; customFieldsPackage.dataTypeSpecified = true; customFieldsPackage.DataValue = new DataValue(); customFieldsPackage.DataValue.Items = new[] { customFieldsc }; customFieldsPackage.DataValue.ItemsElementName = new[] { ItemsChoiceType.ObjectValue }; account.CustomFields = new GenericObject { GenericFields = new[] { customFieldsPackage }, ObjectType = new RNObjectType { TypeName = CustomField.AccountCustomFieldsTypeName } }; ClientInfoHeader clientInfoHeader = new ClientInfoHeader(); clientInfoHeader.AppID = OracleRightNowOOOAddInNames.OutOfOfficeAddIn; RNObject[] contactObjects = new RNObject[] { account }; UpdateProcessingOptions updateProcessingOptions = new UpdateProcessingOptions(); _rightNowClient.Update(clientInfoHeader, contactObjects, updateProcessingOptions); return(true); } catch (Exception e) { MessageBox.Show(OOOExceptionMessages.UnexpectedError, Common.Common.ErrorLabel, MessageBoxButtons.OK, MessageBoxIcon.Error); Error(e.Message, e.StackTrace); } Debug("RightNowConnectService - updateCustomFields() - Exit"); return(false); }
public void SetSelectedStaff(object selectedItem) { SelectedStaff = (StaffAccount)selectedItem; }