public void test_connection_ef() { Console.WriteLine(TimeZoneInfo.Local.Id); Database.SetInitializer(new DropCreateDatabaseAlways<HRContext>()); using (var hr_context = new HRContext()) //using(var tran = hr_context.Database.BeginTransaction()) { //hr_context.Database.CreateIfNotExists(); //var dhing = (from x in hr_context.Players // where x.Name == "Dhing" // select x).FirstOrDefault(); //dhing.CreatedDate = DateTime.Now; var p = new Player() { Id= 3, Name = "Dhing", CreatedDate = DateTime.Now }; hr_context.Players.Add(p); hr_context.SaveChanges(); //tran.Commit(); } }
public async Task <IHttpActionResult> Get() { using (var context = new HRContext()) { return(Ok(await context.UserTypeEntity.ToListAsync())); } }
public async Task <IHttpActionResult> Post([FromBody] User user) { using (var context = new HRContext()) { var userType = await context.UserTypeEntity.FirstOrDefaultAsync(b => b.Id == user.UserTypeId); if (userType == null) { return(NotFound()); } var newUser = context.UserEntity.Add(new User { UserTypeId = userType.Id, Name = user.Name, LastName = user.LastName, Email = user.Email, Password = user.Password.ToSHA256() }); await context.SaveChangesAsync(); return(Ok(newUser)); } }
static void Main(string[] args) { // Starting interactive prompt using (var ctx = new HRContext()) { Boolean active = true; while (active) { Console.Out.WriteLine("1. Make a trade (and save)"); Console.Out.WriteLine("2. Delete all rows"); Console.Out.WriteLine("3. Display trader by ID"); Console.Out.WriteLine("4. Display trades by trader last name"); Console.Out.WriteLine("5. Display leaderboard"); Console.Out.WriteLine("6. Quit"); Console.Out.Write("What would you like to do? "); string option = Console.ReadLine(); Console.WriteLine(option); switch (option) { // Task 2 case "1": Task2(ctx); break; // Task 3 case "2": Task3(ctx); break; // Task 4 case "3": Task4(ctx); break; // Task 5 case "4": Task5(ctx); break; // Task 6 case "5": Task6(ctx); break; case "6": Console.Out.WriteLine("Exited."); active = false; break; default: Console.Out.WriteLine("Invalid option. Try again!"); break; } } } }
// Task 3: Delete all traders and trades public static void Task3(HRContext ctx) { Console.WriteLine("Transaction started"); ctx.Persons.RemoveRange(ctx.Persons); ctx.Trades.RemoveRange(ctx.Trades); Console.WriteLine("All trades and traders deleted from the database."); ctx.SaveChanges(); }
// private RoleManager<RegUser> _roleManager; public UserController(HRContext ctx, UserManager <RegUser> UserManager, IMapper mapper) { _ctx = ctx; _userManager = UserManager; _mapper = mapper; //_roleManager = RoleManager; }
public static void Task2(HRContext ctx) { Console.Out.Write("Stock name: "); String stockName = Console.ReadLine(); Console.Out.Write("DateTime (YYYY-MM-DD): "); DateTime.TryParse(Console.ReadLine(), out DateTime tempDate); Console.Out.Write("Price: "); Decimal.TryParse(Console.ReadLine(), out Decimal price); Console.Out.Write("Number of Shares: "); int.TryParse(Console.ReadLine(), out int shares); Console.Out.WriteLine("Choose one:"); Console.Out.WriteLine("1. Existing trader"); Console.Out.WriteLine("2. New trader"); String newOrExisting = Console.ReadLine(); if (newOrExisting.Equals("1")) { Console.Out.Write("Link trade to trader with which ID? "); long.TryParse(Console.ReadLine(), out long traderID); Person person1 = ctx.Persons.Where(p => p.PersonId == traderID).FirstOrDefault(); //Trade2 trade = new Trade2() { stockName = stockName, purchaseDate = tempDat e, purchasePrice = price, shares = shares, Trade2Id = traderID }; //Trade2 trade = new Trade2() { stockName = stockName, purchaseDate = tempDate, purchasePrice = price, shares = shares, trader = person1 }; Trade2 trade = new Trade2(stockName, tempDate, price, shares, person1); ctx.Trades.Add(trade); ctx.SaveChanges(); Console.WriteLine("Trade saved."); } else if (newOrExisting.Equals("2")) { Console.Out.Write("Trader first name: "); String traderFirstName = Console.ReadLine(); Console.Out.Write("Trader last name: "); String traderLastName = Console.ReadLine(); Console.Out.Write("Trader phone: "); String phone = Console.ReadLine(); Person person2 = new Person() { firstname = traderFirstName, lastname = traderLastName, phone = phone }; //Trade2 trade = new Trade2() { stockName = stockName, purchaseDate = tempDate, purchasePrice = price, shares = shares, trader = person2 }; Trade2 trade = new Trade2(stockName, tempDate, price, shares, person2); ctx.Trades.Add(trade); ctx.Persons.Add(person2); ctx.SaveChanges(); Console.WriteLine("Trade and person saved."); } else { Console.Out.WriteLine("Invalid option. Try again"); } }
public BaseRepository(HRContext context) { ctx = context; // if (Properties.Settings.Default.Debug) // { //ctx.Database.Log = message => System.Diagnostics.Trace.TraceInformation(message); // } }
public void PopulateRoleDropDownList(HRContext _context, object selectedRole = null) { var RoleQuery = from r in _context.Roles orderby r.Title // Sort by name. select r; RoleNameSL = new SelectList(RoleQuery.AsNoTracking(), "Id", "Title", selectedRole); }
public void PopulatePositionDropDownList(HRContext _context, object selectedDepartment = null) { var PositionQuery = from r in _context.Positions orderby r.Title // Sort by name. select r; PositionNameSL = new SelectList(PositionQuery.AsNoTracking(), "Id", "Title", selectedDepartment); }
public async Task <IHttpActionResult> Get() { using (var context = new HRContext()) { var list = await context.UserEntity.ToListAsync(); list.ForEach(a => a.Password = string.Empty); return(Ok(list)); } }
public void PopulateRegionDropDownList(HRContext _context, object selectedRegion = null) { var RegionsQuery = from r in _context.Regions orderby r.Name // Sort by name. select r; RegionNameSL = new SelectList(RegionsQuery.AsNoTracking(), "Id", "Name", selectedRegion); }
public void PopulateDepartmentDropDownList(HRContext _context, object selectedDepartment = null) { var DepartmentQuery = from r in _context.Departments orderby r.Name // Sort by name. select r; DepartmentNameSL = new SelectList(DepartmentQuery.AsNoTracking(), "Id", "Name", selectedDepartment); }
/* * public void PopulateEmployeeDropDownList(HRContext _context, object selectedEmployee = null) * { * var EmployeeQuery = from e in _context.Employees orderby e.LastName select e; * EmployeeSL = new SelectList(EmployeeQuery.AsNoTracking(), "Id", "FullName", selectedEmployee); * } */ public void PopulateEmployeeDropDownList(HRContext _context, object selectedEmployee = null) { UserId = Convert.ToInt32(User.Claims .Where(c => c.Type == ClaimTypes.PrimarySid) .Select(c => c.Value) .First()); //Rethink this. This will probably break when editing? Wait... Nevermind. var EmployeeQuery = from e in _context.Employees where e.Id == UserId orderby e.LastName select e; EmployeeSL = new SelectList(EmployeeQuery.AsNoTracking(), "Id", "FullName", selectedEmployee); }
public AccountController( UserManager <RegUser> userManager, SignInManager <RegUser> signInManager, IEmailSender emailSender, ILoggerFactory loggerFactory, HRContext ctx) { _userManager = userManager; _signInManager = signInManager; _emailSender = emailSender; _logger = loggerFactory.CreateLogger <AccountController>(); _ctx = ctx; }
public void PopulateManagerDropDownList(HRContext _context, object selectedEmployee = null) { var ManagerQuery = from r in _context.Employees orderby r.LastName // Sort by name. select r; ManagerNameSL = new SelectList((from r in ManagerQuery.ToList() select new { Id = r.Id, FullName = r.LastName + ", " + r.FirstName }), "Id", "FullName", selectedEmployee); }
public List <EmployeeDto> GetEmployee(string keyWord) { using (var context = new HRContext()) { return((from employee in context.Employees where employee.PersonalCode.ToString().Contains(keyWord) select new EmployeeDto { FirstName = employee.FirstName, LastName = employee.LastName, PersonalCode = employee.PersonalCode, NationalCode = employee.NationalCode }).ToList()); } }
public async Task <IHttpActionResult> Get(int id) { using (var context = new HRContext()) { var user = await context.UserEntity.FirstOrDefaultAsync(y => y.Id == id); if (user is null) { return(this.NotFound("User not found")); } user.Password = string.Empty; return(Ok(user)); } }
public async Task <IHttpActionResult> Post([FromBody] UserType usertype) { using (var context = new HRContext()) { var newUserType = context.UserTypeEntity.Add(new UserType { Description = usertype.Description, Title = usertype.Title }); await context.SaveChangesAsync(); return(Ok(newUserType)); } }
// Task 5: Retrieve all traders by last name // Notes: Using option 1 to generate few trades with the same trader's last name then use option 4 to view all of them public static void Task5(HRContext ctx) { Console.Out.Write("Find all traders with which last name? "); String personName = Console.ReadLine(); Console.WriteLine("Query completed with following results:"); var traders = ctx.Persons.Where(p => p.lastname == personName).Include(p => p.trades).ToList(); foreach (var p in traders) { Console.WriteLine(" - " + p.firstname + " " + p.lastname + " with ID: " + p.PersonId); foreach (var trade in p.trades) { Console.WriteLine(" Name: " + trade.stockName + " with purchase price " + trade.purchasePrice + " on " + trade.purchaseDate); } } }
public void PopulateReviewingEmployeeDropDownList(HRContext _context, object selectedEmployee = null) { var EmployeeQuery = from r in _context.Employees orderby r.LastName // Sort by name. select r; ReviewingEmployeeNameSL = new SelectList((from r in EmployeeQuery.ToList() select new { Id = r.Id, FullName = r.FirstName + " " + r.LastName }), "Id", "FullName", selectedEmployee); //EmployeeQuery.AsNoTracking(), //"Id", "FirstName", selectedEmployee); }
public ActionResult LoginForm(UserLogin login, string returnUrl) { string message = ""; string password = login.Password; usernameNow = login.Username; using (HRContext context = new HRContext()) { var getUser = context.UsersDbSet.Where(c => c.Username == login.Username || c.Email == login.Username).SingleOrDefault(); if (getUser != null) { if (Crypto.Hash(password) == getUser.Password) { int timeout = login.RememberMe ? 17280 : 480; var ticket = new FormsAuthenticationTicket(login.Username, login.RememberMe, timeout); string encryptedTicket = FormsAuthentication.Encrypt(ticket); var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); 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 = "It seems that you have entered a wrong password, please check your inputs and try again."; } } else { message = "There is no such username saved in the system, please make sure the you entered the correct spelling."; } } ViewBag.Message = message; return(View(login)); }
// Task 4: Retrieve trader information by ID public static void Task4(HRContext ctx) { Console.Out.Write("Find trader for which ID? "); long.TryParse(Console.ReadLine(), out long personID); Person person3 = ctx.Persons.Where(p => p.PersonId == personID).FirstOrDefault(); Console.WriteLine("Trader Name: " + person3.firstname + " " + person3.lastname); Console.WriteLine("Trader ID: " + person3.PersonId + " and Trader phone: " + person3.phone); var trades = (from b in ctx.Trades orderby b.purchaseDate where b.trader.PersonId == person3.PersonId select b).ToList(); Console.WriteLine(" has " + trades.Count + " trades: "); foreach (Trade2 trade in trades) { Console.WriteLine(" Name: " + trade.stockName + " with purchase price " + trade.purchasePrice + " on " + trade.purchaseDate); } }
protected override void OnContentRendered(EventArgs e) { base.OnContentRendered(e); if (_hasShown) { return; } _hasShown = true; using (var context = new HRContext()) { var employeeCollection = new ObservableCollection <Employees>(context.Employees.AsQueryable()); EmployeeGrid.ItemsSource = employeeCollection; employeeCollection.CollectionChanged += EmployeeCollection_CollectionChanged; } }
// Task 6: Displaying the leader board. // Notes: Using option 1 to generate few trades then use option 6 to view their gain in descending order public static void Task6(HRContext ctx) { Console.Out.WriteLine("Displaying leaderboard."); String hql = "select t.trader_PersonID, sum((s.stockclose-t.purchasePrice)*t.shares) as gain, (sum((s.stockclose-t.purchasePrice)*t.shares)/sum(t.purchasePrice) * 100) as percentIncrease " + "from dbo.Trade2 as t left join Demo.Stock as s on t.stockName = s.Name where s.TransDate = TO_DATE('2017/08/10', 'yyyy/mm/dd') " + "group by t.trader_PersonID " + "order by gain desc"; var query = ctx.Database.SqlQuery <TestEntity>(hql).ToList(); Console.WriteLine("Trader\t\tGain\t\tPercent Increase"); foreach (TestEntity aRow in query) { int id5 = (int)aRow.trader_PersonID; Person person5 = ctx.Persons.Where(p => p.PersonId == id5).FirstOrDefault(); Decimal gain = (Decimal)aRow.gain; Decimal percentIncrease = (Decimal)aRow.percentIncrease; Console.WriteLine(person5.firstname + " " + person5.lastname + "\t$" + gain + "\t" + Math.Ceiling(percentIncrease * 100) / 100 + "%"); } }
/// <summary> /// Registers the type mappings with the Unity container. /// </summary> /// <param name="container">The unity container to configure.</param> /// <remarks> /// There is no need to register concrete types such as controllers or /// API controllers (unless you want to change the defaults), as Unity /// allows resolving a concrete type even if it was not previously /// registered. /// </remarks> public static void RegisterTypes(IUnityContainer container) { // NOTE: To load from web.config uncomment the line below. // Make sure to add a Unity.Configuration to the using statements. // container.LoadConfiguration(); // TODO: Register your type's mappings here. // container.RegisterType<IProductRepository, ProductRepository>(); HRContext hr = new HRContext(); hr.Database.Initialize(force: false); var unitOfWorkHr = new UnitOfWork(hr); container .RegisterType <HRContext>("HRContext", new PerRequestLifetimeManager()) .RegisterType <DbContext, DocumentsExplorerContext>(new PerRequestLifetimeManager()) .RegisterType <IApplicationContext, ApplicationContext>() .RegisterType(typeof(IRepositoryAsync <>), typeof(Repository <>)) .RegisterType <IUnitOfWorkAsync, UnitOfWork>(new PerRequestLifetimeManager()) .RegisterType <IMainCategoryBLL, MainCategoryBLL>() .RegisterType <ICouncilTypeBLL, CouncilTypeBLL>() .RegisterType <ISubCategoryBLL, SubCategoryBLL>() .RegisterType <ICountryBLL, CountryBLL>() .RegisterType <ICouncilMemberBLL, CouncilMemberBLL>() .RegisterType <IRoundBLL, RoundBLL>() .RegisterType <IMinutesOfMeetingBLL, MinutesOfMeetingBLL>() .RegisterType <IMeetingBLL, MeetingBLL>() .RegisterType <IAttachmentBLL, AttachmentBLL>() .RegisterType <ICompanyBLL, CompanyBLL>() .RegisterType <IActivitySectorBLL, ActivitySectorBLL>() .RegisterType <IDecisionTypeBLL, DecisionTypeBLL>() .RegisterType <IReferenceTypeBLL, ReferenceTypeBLL>() .RegisterType <IDepartmentBLL, DepartmentBLL>() .RegisterType <IDecisionExecutionBLL, DecisionExecutionBLL>() .RegisterType <IDepartmentResponsibleBLL, DepartmentResponsibleBLL>() .RegisterType <IDecisionBLL, DecisionBLL>() .RegisterType <INotificationBLL, NotificationBLL>() .RegisterType <IEmployeeService, EmployeeService>(new PerRequestLifetimeManager(), new InjectionConstructor(new Repository.Pattern.Ef6.Repository <Employee>(hr, unitOfWorkHr, new ApplicationContext()), unitOfWorkHr)) .RegisterType <IDepartmentService, DepartmentService>(new PerRequestLifetimeManager(), new InjectionConstructor(new Repository.Pattern.Ef6.Repository <AAAID.HR.Entities.Department>(hr, unitOfWorkHr, new ApplicationContext()), unitOfWorkHr)); }
void Application_PostAuthenticateRequest() { if (Request.IsAuthenticated) { var userIdentity = (ClaimsIdentity)User.Identity; var userClaims = userIdentity.Claims.ToArray(); var upn = userClaims.SingleOrDefault(n => n.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn").Value; var loggedInCasId = upn.Split('@')[0]; // Always add the username userIdentity.AddClaim(new Claim(ClaimTypes.Name, upn)); // Now see if the logged in user is an HrPerson (Admin). IQueryable <string> adminCasIds; using (HRContext db = new HRContext()) { var isHrPerson = false; adminCasIds = db.Participants.Where(n => n.IsHrPerson).Select(n => n.CasId); foreach (var adminCasId in adminCasIds) { if (adminCasId == loggedInCasId) { userIdentity.AddClaim(new Claim(ClaimTypes.Role, "Admin")); isHrPerson = true; break; } } if (!isHrPerson) { userIdentity.AddClaim(new Claim(ClaimTypes.Role, "User")); } } } }
public JobController(HRContext ctx) { _ctx = ctx; _jobRepository = new JobRepository(ctx); }
public ContactController(HRContext context) { db = context; }
public SearchController(HRContext context) { db = context; }
public ProjectRepository(HRContext hR) { db = hR; }