public async Task <IActionResult> AddEmployee([FromBody] InputEmployee input) { var existing = await _context.Employees.FindAsync(Misc.StripCpf(input.Cpf)); var exists = existing != null; if (exists) { ModelState.AddModelError(nameof(InputEmployee.Cpf), "CPF já existente"); return(Conflict(ModelState)); } var occupation = await _context.Occupations.FindAsync(input.OccupationId); if (occupation == null) { ModelState.AddModelError(nameof(InputEmployee.OccupationId), "Ocupação não encontrada"); return(NotFound(ModelState)); } Employee employee = input.ToModel(occupation, _passwordHash); await _context.Users.AddAsync(employee.User); await _context.Employees.AddAsync(employee); await _context.SaveChangesAsync(); return(Ok(new OutputEmployee(employee))); }
public async Task <IActionResult> UpdateSelf([FromBody] InputEmployee input) { var currentEmployee = await _currentUserInfo.GetCurrentEmployee(); if (currentEmployee == null) { return(Unauthorized()); } if (input.Cpf != currentEmployee.UserId) { ModelState.AddModelError("", "Cpf changes are not allowed"); return(BadRequest(ModelState)); } if (input.AccessLevel != currentEmployee.AccessLevel) { ModelState.AddModelError("", "Self access level changes are not allowed"); return(BadRequest(ModelState)); } return(await UpdateEntry(input)); }
//录单汇总 private void BtnInputOrders_Click(object sender, EventArgs e) { var db_new = new BathDBDataContext(connectionString); InputEmployee inputEmployee = new InputEmployee(db_new); if (inputEmployee.ShowDialog() != DialogResult.OK) return; if (!BathClass.getAuthority(db_new, inputEmployee.emplyee, "录单汇总")) { BathClass.printErrorMsg("不具有权限"); return; } TableOrderTableForm orderTableForm = new TableOrderTableForm(connectionString, inputEmployee.emplyee); orderTableForm.ShowDialog(); }
private async Task <IActionResult> UpdateEntry(InputEmployee input) { string cpf = input.Cpf; var entry = await _context.Employees .FindAsync(cpf); await _context.Entry(entry) .Reference(row => row.User) .LoadAsync(); if (entry == null) { return(NotFound()); } var occupation = await _context.Occupations.FindAsync(input.OccupationId); if (occupation == null) { return(NotFound()); } Employee updated = input.ToModel(occupation, _passwordHash); entry.User.Name = updated.User.Name; entry.User.SocialName = updated.User.SocialName; entry.User.BirthDate = updated.User.BirthDate; entry.User.Phone = updated.User.Phone; entry.User.Email = updated.User.Email; entry.Gender = updated.Gender; entry.Rg = updated.Rg; entry.OccupationId = updated.OccupationId; entry.AccessLevel = updated.AccessLevel; // we ignore password changes if the input // did not request one. if (input.Password != null) { entry.User.Password = updated.User.Password; } await _context.SaveChangesAsync(); return(Ok(new OutputEmployee(entry))); }
public async Task <IActionResult> UpdateGiven([FromBody] InputEmployee input) { var currentEmployee = await _currentUserInfo.GetCurrentEmployee(); if (currentEmployee == null) { return(Unauthorized()); } if (input.Cpf == currentEmployee.UserId) { ModelState.AddModelError("", "Self updates must be done through the " + "/api/employee/info endpoint"); return(BadRequest(ModelState)); } return(await UpdateEntry(input)); }
private async Task <List <InputEmployee> > GetInputEmployees(List <Employee> employees, IDependentRepository dependentRepository) { var inputEmployees = new List <InputEmployee>(); foreach (var employee in employees) { var eTemp = new InputEmployee(); eTemp.Id = employee.Id; eTemp.Name = $"{employee.FirstName} {employee.LastName}"; employee.Dependents = await dependentRepository.GetAllEmployeeDependentsAsync(employee.Id); foreach (var d in employee.Dependents) { var dTemp = new InputDependent(); dTemp.Id = d.Id; dTemp.Name = $"{d.FirstName} {d.LastName}"; eTemp.InputDependents.Add(dTemp); } inputEmployees.Add(eTemp); } return(inputEmployees); }
//自动点单 private void ExpenseOrder_Click(object sender, EventArgs e) { var db = new BathDBDataContext(connectionString); InputEmployee inputEmployee = new InputEmployee(db); if (inputEmployee.ShowDialog() != DialogResult.OK) return; Employee server = inputEmployee.emplyee; if (!BathClass.getAuthority(db, server, "完整点单") && !BathClass.getAuthority(db, server, "可见本人点单")) { BathClass.printErrorMsg("权限不够,不能访问!"); return; } List<int> sList = new List<int>(); sList.Add(2); sList.Add(6); InputSeatForm inputSeatForm = new InputSeatForm(sList); if (inputSeatForm.ShowDialog() != DialogResult.OK) return; //var m_Seat = db.Seat.FirstOrDefault(x => x.Equals(inputSeatForm.m_Seat)); //m_Seat.ordering = true; //db.SubmitChanges(); //修改 //OrderForm orderForm = new OrderForm(inputSeatForm.m_Seat, server, connectionString, true); //orderForm.ShowDialog(); //m_Seat.ordering = false; //db.SubmitChanges(); }