public async Task <IActionResult> Edit(string id, [Bind("RegUserName,statusOfUser,RegUserLastName,RegUserCity,RegUserCountry,LocationChange,RegUserPartFull,WorkXp,RegUserKeyword,RegUserSex,RegUserDoB,RegUserAdditionalInfo,Id,UserName,NormalizedUserName,Email,NormalizedEmail,EmailConfirmed,PasswordHash,SecurityStamp,ConcurrencyStamp,PhoneNumber,PhoneNumberConfirmed,TwoFactorEnabled,LockoutEnd,LockoutEnabled,AccessFailedCount")] RegUser regUser)
        {
            if (id != regUser.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(regUser);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RegUserExists(regUser.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View("~/Views/BackOffice/User/Index.cshtml", regUser));
        }
Exemplo n.º 2
0
    public async Task <bool> CommitAsync()
    {
        var eventLogs = _context.LogEvents();
        await _context.SaveChangesAsync();

        await PublishEventsAsync(eventLogs);

        return(true);
    }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("JobId,JobName,JobDesc,JobCity,JobCountry,JobCategories,JobSalary,JobReqXp,JobPartFull,JobKeyword")] Job job)
        {
            if (ModelState.IsValid)
            {
                _jobctx.Add(job);
                await _jobctx.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View("~/Views/General/Job/Index.cshtml", job));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("CompanyName,CompanyDesc,CompanyCity,CompanyCountry,CompanyPhone,CompanyEmail,CompanyWebSite")] Company company)
        {
            if (ModelState.IsValid)
            {
                _context.Add(company);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View("~/Views/BackOffice/Company/Index.cshtml", company));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                _context.Add(employee);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(employee));
        }
        public async Task <IActionResult> Create([Bind("CompanyId,Name,Description,City,Country,Phone,EmailAddress,Website")] Company company)
        {
            if (ModelState.IsValid)
            {
                _context.Add(company);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(company));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Create([Bind("Name,SurName,City,Country,PartTime_FullTime,WorkExperience,StatusOfUser,DateOfBirth,Sex,NoteField,DateCreated,Id,UserName,NormalizedUserName,Email,NormalizedEmail,EmailConfirmed,PasswordHash,SecurityStamp,ConcurrencyStamp,PhoneNumber,PhoneNumberConfirmed,TwoFactorEnabled,LockoutEnd,LockoutEnabled,AccessFailedCount")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                user.DateCreated = DateTime.Now;
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(user));
        }
Exemplo n.º 8
0
        public async Task <IActionResult> Create([Bind("JobId,Name,Description,City,Country,PartTime_FullTime,Keywords,CreatedById")] JobPosition jobPosition)
        {
            if (ModelState.IsValid)
            {
                _context.Add(jobPosition);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewData["CreatedById"] = new SelectList(_context.RegUsers, "Id", "Id", jobPosition.CreatedById);
            return(View(jobPosition));
        }
Exemplo n.º 9
0
        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));
            }
        }
Exemplo n.º 10
0
    public async Task SeedAsync()
    {
        if (_context.Set <Department>().Any())
        {
            return;
        }

        var employees   = GetEmployees();
        var departments = GetDepartments();
        var jobs        = GetJobs();

        employees[0].AssignJob(departments[0], jobs[0], DateTime.Parse("2018-07-01"));
        employees[1].AssignJob(departments[1], jobs[1], DateTime.Parse("2018-07-01"));
        employees[2].AssignJob(departments[2], jobs[2], DateTime.Parse("2018-07-01"));
        employees[3].AssignJob(departments[3], jobs[2], DateTime.Parse("2018-07-15"));
        employees[4].AssignJob(departments[4], jobs[2], DateTime.Parse("2018-08-04"));
        employees[5].AssignJob(departments[1], jobs[3], DateTime.Parse("2018-08-04"));
        employees[6].AssignJob(departments[2], jobs[6], DateTime.Parse("2018-08-04"));
        employees[7].AssignJob(departments[3], jobs[4], DateTime.Parse("2018-08-04"));
        employees[8].AssignJob(departments[3], jobs[4], DateTime.Parse("2018-08-04"));
        employees[9].AssignJob(departments[3], jobs[4], DateTime.Parse("2018-08-04"));
        employees[10].AssignJob(departments[4], jobs[5], DateTime.Parse("2018-08-04"));
        employees[11].AssignJob(departments[4], jobs[5], DateTime.Parse("2018-08-04"));

        _context.Set <Employee>().AddRange(employees);
        _context.Set <Department>().AddRange(departments);
        _context.Set <Job>().AddRange(jobs);

        _context.LogEvents();
        await _context.SaveChangesAsync();
    }
Exemplo n.º 11
0
        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));
            }
        }
Exemplo n.º 12
0
 //添加
 public async Task <int> Add(T t)
 {
     db.Set <T>().Add(t);
     return(await db.SaveChangesAsync());
 }
Exemplo n.º 13
0
        public async Task <int> Add(T entity)
        {
            await _context.Set <T>().AddAsync(entity);

            return(await _context.SaveChangesAsync());
        }
Exemplo n.º 14
0
 public async Task SaveAsync()
 {
     await db.SaveChangesAsync();
 }
Exemplo n.º 15
0
    public DatabaseFixture()
    {
        var options = new DbContextOptionsBuilder <HRContext>()
                      .UseInMemoryDatabase(databaseName: "testing_db")
                      .Options;

        Context = new HRContext(options);

        // ... initialize data in the test database ...

        Region region1 = new Region
        {
            Id      = 1,
            Name    = "New York",
            Country = "USA",
            BonusRevenueThreshold = 1000000
        };
        Region region2 = new Region
        {
            Id      = 2,
            Name    = "Texas",
            Country = "USA",
            BonusRevenueThreshold = 2000000
        };

        Role role1 = new Role
        {
            Id    = 1,
            Title = "Role 1"
        };

        Role role2 = new Role
        {
            Id    = 2,
            Title = "Role 2"
        };

        Department department1 = new Department
        {
            Id   = 1,
            Name = "Test Department 1"
        };
        Department department2 = new Department
        {
            Id   = 2,
            Name = "HR"
        };

        Position position1 = new Position
        {
            Id    = 1,
            Title = "Sales Rep"
        };

        Position position2 = new Position
        {
            Id    = 2,
            Title = "Test position 2"
        };

        Employee employee1 = new Employee
        {
            Id                  = 1,
            FirstName           = "Test",
            LastName            = "User",
            DateOfBirth         = new DateTime(),
            Address             = "1 Testing Street",
            PhoneNumber         = "5851231234",
            EmploymentEndDate   = new DateTime(),
            EmploymentStartDate = new DateTime(),
            RegionId            = region1.Id,
            Region              = region1,
            RoleId              = role2.Id,
            Role                = role2,
            Commission          = 10000,
            DepartmentId        = department2.Id,
            Department          = department2,
            PositionId          = position2.Id,
            Position            = position2
        };

        Employee employee2 = new Employee
        {
            Id                  = 2,
            FirstName           = "SpongeBob",
            LastName            = "Square Pants",
            DateOfBirth         = new DateTime(),
            Address             = "124 Conch Street",
            PhoneNumber         = "29998559671349",
            EmploymentEndDate   = new DateTime(),
            EmploymentStartDate = new DateTime(),
            RegionId            = region2.Id,
            Region              = region2,
            RoleId              = role2.Id,
            Role                = role2,
            Commission          = 10000,
            DepartmentId        = department2.Id,
            Department          = department2,
            PositionId          = position1.Id,
            Position            = position1
        };

        Context.Roles.Add(role1);
        Context.Roles.Add(role2);
        Context.Regions.Add(region1);
        Context.Regions.Add(region2);
        Context.Departments.Add(department1);
        Context.Departments.Add(department2);
        Context.Positions.Add(position1);
        Context.Positions.Add(position2);
        Context.Employees.Add(employee1);
        Context.Employees.Add(employee2);
        Context.SaveChangesAsync();
    }
Exemplo n.º 16
0
        public async Task <Dictionary <string, string> > CalculateSalary(Paycheck paystub, bool monthlyBonus, bool quarterlyBonus)
        {
            //Check to see if dates make a correct range
            int dateResult = DateTime.Compare(paystub.PayPeriodStart, paystub.PayPeriodEnd);

            if (dateResult > 0)
            {
                return(new Dictionary <string, string>()
                {
                    { "status", "error" },
                    { "message", "Incorrect Dates" },
                });
            }

            var dates = new List <DateTime>();

            for (var dt = paystub.PayPeriodStart; dt <= paystub.PayPeriodEnd; dt = dt.AddDays(1))
            {
                dates.Add(dt);
            }
            var dates_copy = new List <DateTime>(dates);

            var result = true;

            foreach (DateTime date in dates)
            {
                result = result && !(_context.Paychecks.Any(paycheck => (date >= paycheck.PayPeriodStart && date <= paycheck.PayPeriodEnd)));
            }

            if (!result)
            {
                return(new Dictionary <string, string>()
                {
                    { "status", "error" },
                    { "message", "Payment already calculated for dates" },
                });
            }

            var num_days     = dates_copy.Count;
            int days_in_year = new DateTime(DateTime.Now.Year, 12, 31).DayOfYear - new DateTime(DateTime.Now.Year, 1, 1).DayOfYear;

            var lumpSum    = 0.0;
            int salesRepId = _context.Positions.Where(e => e.Title.Equals("Sales Rep")).First().Id;

            foreach (Employee line in _context.Employees.ToList())
            {
                var base_pay       = CalculateEmployeeBasePay(line.Salary, days_in_year, num_days);
                var bonus_pay      = 0.0;
                var commission_pay = 0.0;

                if (salesRepId == line.PositionId)
                {
                    bonus_pay     += GetIndividualBonus(line);
                    commission_pay = GetIndividualCommission(line);
                }

                if (monthlyBonus)
                {
                    bonus_pay += GetMonthlyBonus(line);
                }

                if (quarterlyBonus)
                {
                    bonus_pay += GetQuarterlyBonus(line);
                }

                //Make the paycheck object and Save
                var PayStubNew = new Paycheck();
                PayStubNew.EmployeeId     = line.Id;
                PayStubNew.Employee       = line;
                PayStubNew.IssueDate      = paystub.PayPeriodEnd;
                PayStubNew.BasePay        = base_pay;
                PayStubNew.BonusPay       = bonus_pay;
                PayStubNew.Commission     = commission_pay;
                PayStubNew.PayPeriodStart = dates_copy[0];
                PayStubNew.PayPeriodEnd   = dates_copy[dates_copy.Count() - 1];

                lumpSum += base_pay + bonus_pay + commission_pay;

                _context.Paychecks.Add(PayStubNew);
                await _context.SaveChangesAsync();
            }

            var mapping = new Dictionary <string, string>()
            {
                { "lumpSum", lumpSum.ToString() },
                { "startDate", dates_copy[0].ToString() },
                { "endDate", dates_copy[dates_copy.Count() - 1].ToString() },
                { "status", "success" }
            };

            return(mapping);
        }