public async Task <IActionResult> EditNew(int id) { if (_signInManager.Context.User.Identity.IsAuthenticated) { if (HttpContext.User.IsInRole("Hr")) { if (id == 0) { return(BadRequest()); } await Initializer.InitialLayout("Work Places", ViewBag, _db, _signInManager, "New/Edit"); WorkModel Work = await _db.Works .Where(w => w.Id == id) .Include(w => w.Employee) .Include(w => w.BranchPosition) .ThenInclude(w => w.Branch) .Include(w => w.BranchPosition) .ThenInclude(w => w.Position) .Select(w => new WorkModel { Id = w.Id, BranchPositionId = w.BranchPositionId, EnterTime = w.EnterTime, LeaveTime = Convert.ToDateTime(w.LeaveTime), Reason = w.Reason, Employee = w.Employee, EmployeeId = w.EmployeeId }) .FirstOrDefaultAsync(); BranchPosition branchPosition = await _db.BranchPositions .Where(bp => bp.Id == Work.BranchPositionId) .Include(bp => bp.Position) .ThenInclude(p => p.Department) .FirstOrDefaultAsync(); Work.BranchPosition = branchPosition; Position position = branchPosition.Position; Work.BranchPositions = await _db.BranchPositions .Where(bp => bp.PositionId == position.Id) .Include(bp => bp.Position) .Include(bp => bp.Branch) .ThenInclude(b => b.Company) .ThenInclude(c => c.Holding) .ToListAsync(); Work.Departments = await _db.Departments.ToListAsync(); Work.Position = position; Work.Holdings = await _db.Holdings.ToListAsync(); return(View(Work)); } } return(RedirectToAction("Forbidden", "Error")); }
public async Task <IActionResult> AddNew(WorkModel model) { if (_signInManager.Context.User.Identity.IsAuthenticated) { if (HttpContext.User.IsInRole("Hr")) { await Initializer.InitialLayout("Work Places", ViewBag, _db, _signInManager, "Add New work places"); Employee employee = await _db.Employees .Where(e => e.Id == model.EmployeeId) .FirstOrDefaultAsync(); List <Holding> holdings = await _db.Holdings.ToListAsync(); List <Department> departments = await _db.Departments.ToListAsync(); WorkModel workModel = new WorkModel { EmployeeId = employee.Id, Employee = employee, Holdings = holdings, Departments = departments }; if (ModelState.IsValid) { BranchPosition branchPosition = await _db.BranchPositions .Where(bp => bp.PositionId == model .PositionId && bp.BranchId == model.BranchId) .FirstOrDefaultAsync(); Work work = new Work { BranchPositionId = branchPosition.Id, EnterTime = model.EnterTime, EmployeeId = model.EmployeeId }; await _db.Works.AddAsync(work); await _db.SaveChangesAsync(); return(Redirect("/Payroll/Work/Works/" + workModel.EmployeeId)); } else { workModel.BranchId = model.BranchId; workModel.PositionId = model.PositionId; workModel.EnterTime = model.EnterTime; return(View(workModel)); } } } return(RedirectToAction("Forbidden", "Error")); }
public bool PositionChanged() { if (BranchPosition.IsWorldPosition == false) { return(false); } BranchPosition.BoundsOffset = Origin.rect.size / 2; if (Origin.position != BranchPosition.GetPositionIn(Camera, Canvas)) { return(true); } return(false); }
/// <summary> /// Updates the direction of the branch based on the quadrant the origin is currently located in. /// </summary> private void UpdateDirection() { if (BranchPosition.IsWorldPosition) { BranchPosition.BoundsOffset = Origin.rect.size / 2; Origin.position = BranchPosition.GetPositionIn(Camera, Canvas); } var relativePos = Origin.anchoredPosition - Target.anchoredPosition; var dir = new Vector3(Mathf.Sign(relativePos.x), Mathf.Sign(relativePos.y), 1f); if (dir.Equals(CurrentQuadrant)) { return; } CurrentQuadrant = dir; SetOriginScale(); }
public static async Task CreateBP(Branch branch, Position position, PayroleDbContext db) { if (branch == null) { if (position != null) { List <Branch> branches = await db.Branchs.ToListAsync(); foreach (Branch b in branches) { BranchPosition bp = new BranchPosition { BranchId = b.Id, PositionId = position.Id }; await db.BranchPositions.AddAsync(bp); await db.SaveChangesAsync(); } } } else { List <Position> positions = await db.Positions.ToListAsync(); foreach (Position p in positions) { BranchPosition bp = new BranchPosition { BranchId = branch.Id, PositionId = p.Id }; await db.BranchPositions.AddAsync(bp); await db.SaveChangesAsync(); } } }