Beispiel #1
0
        public IActionResult AddCompany(Company company)
        {
            if (!ModelState.IsValid)
            {
                return(View(company));
            }

            _dbContext.Companies.Add(company);
            _dbContext.SaveChanges();
            return(RedirectToAction(nameof(CompanyList)));
        }
        public async Task <IActionResult> Delete(int?id)
        {
            var employee = await _dbContext.Employees.FindAsync(id);

            var workerId = await _dbContext.Users.Where(x => x.EmployeeId == id).Select(x => x.Id).FirstOrDefaultAsync();

            var companyWorkPlaceAbsens = _dbContext.CompanyWorkPlaceAbsens.Where(x => x.CompanyWorkPlace.EmployeeId == employee.ID).ToList();
            var companyWorkPlaceBonus  = _dbContext.CompanyWorkPlaceBonus.Where(x => x.CompanyWorkPlace.EmployeeId == employee.ID).ToList();
            var companyWorkPlace       = _dbContext.CompanyWorkPlaces.Where(x => x.EmployeeId == employee.ID).ToList();
            var workerBonus            = _dbContext.WorkerBonus.Where(x => x.WorkerId == workerId).ToList();
            var workerAbsens           = _dbContext.WorkerAbsens.Where(x => x.WorkerId == workerId).ToList();
            var worker = await _userManager.FindByIdAsync(workerId);

            if (employee != null)
            {
                _dbContext.CompanyWorkPlaceAbsens.RemoveRange(companyWorkPlaceAbsens);
                _dbContext.CompanyWorkPlaceBonus.RemoveRange(companyWorkPlaceBonus);
                _dbContext.CompanyWorkPlaces.RemoveRange(companyWorkPlace);
                _dbContext.WorkerBonus.RemoveRange(workerBonus);
                _dbContext.WorkerAbsens.RemoveRange(workerAbsens);

                RemoveImage(_env.WebRootPath, employee.Image);

                if (worker != null)
                {
                    await _userManager.DeleteAsync(worker);
                }

                _dbContext.Employees.Remove(employee);

                _dbContext.SaveChanges();
                return(RedirectToAction(nameof(EmployeeList)));
            }
            return(BadRequest());
        }
Beispiel #3
0
        public IActionResult AddDepartment(DepartmentViewModel departmentViewModel)
        {
            if (!ModelState.IsValid || departmentViewModel.SelectedCompany == 0)
            {
                departmentViewModel.Companies = _dbContext.Companies.ToList();
                return(View(departmentViewModel));
            }
            Department department = new Department();

            department.CompanyId = departmentViewModel.SelectedCompany;
            department.Name      = departmentViewModel.Name;
            _dbContext.Departments.Add(department);
            _dbContext.SaveChanges();

            return(RedirectToAction(nameof(DepartmentList)));
        }
Beispiel #4
0
        public IActionResult AddStore(StoreViewModel storeViewModel)
        {
            if (!ModelState.IsValid || storeViewModel.SelectedCompany == 0)
            {
                storeViewModel.Companies = _dbContext.Companies.ToList();
                return(View(storeViewModel));
            }
            Store store = new Store();

            store.CompanyId = storeViewModel.SelectedCompany;
            store.Name      = storeViewModel.Name;
            _dbContext.Stores.Add(store);
            _dbContext.SaveChanges();

            return(RedirectToAction(nameof(StoreList)));
        }
        public IActionResult AddPosition(PositionViewModel positionViewModel)
        {
            if (!ModelState.IsValid || positionViewModel.SelectedDepartment == 0)
            {
                positionViewModel.Departments = _dbContext.Departments.ToList();
                return(View(positionViewModel));
            }
            Position position = new Position();

            position.DepartmentId = positionViewModel.SelectedDepartment;
            position.Name         = positionViewModel.Name;
            position.Salary       = positionViewModel.Salary;
            _dbContext.Positions.Add(position);
            _dbContext.SaveChanges();

            return(RedirectToAction(nameof(PositionList)));
        }
        public async Task <IActionResult> AddBonus(string id, AddBonus addBonus)
        {
            var workers = await _userManager.FindByIdAsync(id);

            if (!ModelState.IsValid)
            {
                addBonus.WorkerID      = workers.Id;
                addBonus.WorkerAccount = workers.Account;
                return(View(addBonus));
            }

            WorkerBonus bonus = new WorkerBonus
            {
                WorkerId    = workers.Id,
                BonusSalary = addBonus.BonusSalary,
                BonusDate   = DateTime.Now,
                Reason      = addBonus.Reason
            };

            _dbContext.WorkerBonus.Add(bonus);

            _dbContext.SaveChanges();
            return(RedirectToAction(nameof(WorkerList)));
        }
        public IActionResult UndoWorker(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var worker = _dbContext.Users.Find(id);

            if (worker != null)
            {
                worker.Working = true;
                _dbContext.SaveChanges();
                return(RedirectToAction(nameof(RemovidWorkers)));
            }
            return(BadRequest());
        }
Beispiel #8
0
        public IActionResult AddSale(AvialableStores stores)
        {
            //if (!ModelState.IsValid)
            //{
            //    saleViewModel.Stores = _dbContext.Stores.ToList();
            //    return View(saleViewModel);
            //}

            Sale sale = new Sale();

            sale.StoreId    = stores.StoreId;
            sale.SaleSalary = stores.SaleSalary;
            sale.Date       = stores.Date;

            _dbContext.Sales.Add(sale);
            _dbContext.SaveChanges();

            return(RedirectToAction("StoreList", "Store"));
        }