示例#1
0
        public async Task AddPointsForMatchAsync(Points points)
        {
            var matchPoints = await pointsRepository.FindAsync(p => p.MatchId == points.MatchId, new string[] { "Player" });

            var match = await matchRepository.FindSingleAsync(m => m.MatchId == points.MatchId) ?? throw new NotFoundInDatabaseException();

            var player = await playerRepository.FindSingleAsync(p => p.PlayerId == points.PlayerId) ?? throw new NotFoundInDatabaseException();


            if ((player.TeamId != match.HomeTeamId) && (player.TeamId != match.GuestTeamId))
            {
                throw new ArgumentException();
            }

            if (matchPoints.SingleOrDefault(m => m.PlayerId == points.PlayerId) != null)
            {
                throw new AlreadyInDatabaseException();
            }

            var teamsPoints = new
            {
                homeTeamPoints  = matchPoints.Where(p => p.Player.TeamId == match.HomeTeamId).Sum(s => s.PointsQty),
                guestTeamPoints = matchPoints.Where(p => p.Player.TeamId == match.GuestTeamId).Sum(s => s.PointsQty)
            };

            if (((player.TeamId == match.HomeTeamId) && ((points.PointsQty + teamsPoints.homeTeamPoints) > match.HomeTeamPoints)) ||
                ((player.TeamId == match.GuestTeamId) && ((points.PointsQty + teamsPoints.guestTeamPoints) > match.GuestTeamPoints)))
            {
                throw new ArgumentOutOfRangeException();
            }

            pointsRepository.Add(points);

            await unitOfWork.CompleteAsync();
        }
        public async Task <IActionResult> Create(int employeeId, int timeOfId, IList <Evaluation> evaluations)
        {
            var emp = await _repository.GetEmployee(employeeId);

            var timeOf = await _repository.GetTimesOfEvaluationAndPerformance(timeOfId);

            if (emp == null || timeOf == null)
            {
                ViewBag.ErrorMessage = "لايوجد   بيانات";
                return(View("NotFound"));
            }
            if (ModelState.IsValid)
            {
                foreach (var evaluation in evaluations)
                {
                    _repository.Add <Evaluation>(evaluation);
                }
                await _repository.SavaAll();

                return(RedirectToAction("EmployeeEvaluationsInThisSicle", new { employeeId = employeeId, timeOfId = timeOfId }));
            }
            ViewBag.departmentId = emp.DepartmentId;
            ViewBag.timesOfEvaluationAndPerformanceId = timeOfId;
            ViewBag.employeeId             = emp.Id;
            ViewBag.employeeName           = emp.Name;
            ViewData["evaluationCriteria"] = await _repository.GetEvaluationCriteriasByJopType(emp.JopType);

            return(View());
        }
        public async Task <IActionResult> Create([Bind("Id,Title,FromDate,ToDate,Status")] TimesOfEvaluationAndPerformance timesOf)
        {
            if (ModelState.IsValid)
            {
                _repository.Add <TimesOfEvaluationAndPerformance>(timesOf);
                await _repository.SavaAll();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(timesOf));
        }
        public async Task <IActionResult> Create([Bind("Id,Name")] Department department)
        {
            if (ModelState.IsValid)
            {
                _repository.Add <Department>(department);
                await _repository.SavaAll();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(department));
        }
示例#5
0
        public async Task <IActionResult> Create(EvaluationCriteria evaluationCriteria)
        {
            if (ModelState.IsValid)
            {
                _repository.Add <EvaluationCriteria>(evaluationCriteria);
                await _repository.SavaAll();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(evaluationCriteria));
        }
示例#6
0
        public async Task <IActionResult> Create([Bind("Id,Name,DepartmentId")] Section section)
        {
            if (ModelState.IsValid)
            {
                _repository.Add <Section>(section);
                await _repository.SavaAll();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DepartmentId"] = new SelectList(_repository.GetDepartments().Result, "Id", "Name", section.DepartmentId);
            return(View(section));
        }
示例#7
0
        public async Task <IActionResult> Create(EmployeeCreateViewModel employee)
        {
            if (ModelState.IsValid)
            {
                if (await _repository.IsEmployeeNomberInUse(employee.EmployeeNo))
                {
                    ViewData["DepartmentId"] = new SelectList(_repository.GetDepartments().Result, "Id", "Name", employee.DepartmentId);
                    ViewBag.errormessage     = $"رقم الوظف {employee.EmployeeNo} موجود مسبقا";
                    return(View(employee));
                }
                var employeeMapper = _mapper.Map <Employee>(employee);
                _repository.Add <Employee>(employeeMapper);
                await _repository.SavaAll();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DepartmentId"] = new SelectList(_repository.GetDepartments().Result, "Id", "Name", employee.DepartmentId);
            ViewData["SectionId"]    = new SelectList(_repository.GetDepartments().Result, "Id", "Name", employee.SectionId);
            ViewData["UnitId"]       = new SelectList(_repository.GetDepartments().Result, "Id", "Name", employee.UnitId);
            return(View(employee));
        }
示例#8
0
        public async Task <IActionResult> ManageUserDepartments(int userId, List <AppUserDepartmentsViewModel> models)
        {
            ViewBag.userId = userId;

            var user = await _context.Users.FindAsync(userId);

            if (user == null)
            {
                ViewBag.ErrorMessage = $"المستخدم  = {userId} غير موجود";
                return(View("NotFound"));
            }
            var depts = await _repository.GetAppUserDepartmentsByUserId(user.Id);

            if (depts.Count() > 0)
            {
                foreach (var depart in depts)
                {
                    _repository.Delete <AppUserDepartment>(depart);
                }
                await _repository.SavaAll();
            }

            foreach (var dept in models)
            {
                if (dept.IsSelected)
                {
                    var model = new AppUserDepartment()
                    {
                        DepartmentId = dept.DepartmntId,
                        UserId       = userId
                    };
                    _repository.Add <AppUserDepartment>(model);
                }
            }

            await _repository.SavaAll();

            return(RedirectToAction("Edit", new { id = userId }));
        }
示例#9
0
        public async Task <IActionResult> Create(int employeeId, int timeOfId, Occasion occasion)
        {
            var emp = await _repository.GetEmployee(employeeId);

            var timeOf = await _repository.GetTimesOfEvaluationAndPerformance(timeOfId);

            if (emp == null || timeOf == null)
            {
                ViewBag.ErrorMessage = "لايوجد   بيانات";
                return(View("NotFound"));
            }
            if (ModelState.IsValid)
            {
                _repository.Add <Occasion>(occasion);
                await _repository.SavaAll();

                return(RedirectToAction("EmployeeOccasionsInThisSicle", new { employeeId = employeeId, timeOfId = timeOfId }));
            }
            ViewBag.departmentId = emp.DepartmentId;
            ViewBag.timesOfEvaluationAndPerformanceId = timeOfId;
            ViewBag.employeeId   = emp.Id;
            ViewBag.employeeName = emp.Name;
            return(View());
        }
        public async Task <IActionResult> Create(List <BusinessAndAchievementCreateModelView> models)
        {
            if (ModelState.IsValid)
            {
                var modelsMapper = _mapper.Map <List <BusinessAndAchievement> >(models);
                int empId        = 0;
                int timeOf       = 0;
                var businesses   = await _repository.GetBusinessAndAchievements();

                int count = businesses.Count() + 1;
                foreach (var model in modelsMapper)
                {
                    model.Id = count;
                    _repository.Add <BusinessAndAchievement>(model);
                    empId  = model.EmployeeId;
                    timeOf = model.TimesOfEvaluationAndPerformanceId;
                    count++;
                }
                await _repository.SavaAll();

                return(RedirectToAction("WorksByEmployee", new { employeeId = empId, timesOfEvaluationAndPerformanceId = timeOf }));
            }
            return(View(models));
        }
 public void Add(IPoint3D instance)
 {
     m_Repository.Add(instance);
 }