public async Task <IActionResult> Put([FromBody] BindClient command) { if (await _context.Set <ClientWorkGroup>().AnyAsync(x => x.ClientId == command.ClientId)) { return(BadRequest("Клиет закреплён за другой группой")); } var workGroup = await _context.Set <WorkGroup>() .FirstOrDefaultAsync(x => x.Id == command.WorkgroupId); if (workGroup == null) { return(BadRequest("Группа не найдёна")); } workGroup.BindClient(command); await _context.SaveChangesAsync(); var result = new WorkGroupDto() { Id = workGroup.Id, Title = workGroup.Title, EscortManagerId = workGroup.EscortManagerId ?? 0, RegionalManagerId = workGroup.RegionalManagerId ?? 0 }; return(Ok(result)); }
public async Task <ActionResult <Client> > Post([FromBody] BindClient bindClient) { try { if (bindClient != null) { if (bindClient.RecruiterId < 1) { return(BadRequest()); } var newClient = new Client() { ContactPerson = bindClient.ContactPerson, CompanyName = bindClient.CompanyName, Email = bindClient.Email, TelephoneOffice = bindClient.TelephoneOffice, TelephoneMobile = bindClient.TelephoneMobile, Designation = bindClient.Designation, Remarks = bindClient.Remarks, Address = bindClient.Address }; if (bindClient.RecruiterId > 0) { newClient.Recruiter = await _context.Recruiters.FirstOrDefaultAsync(r => r.RecruiterId == bindClient.RecruiterId); } _context.CrmClients.Add(newClient); await _context.SaveChangesAsync(); var insertedClient = _context.CrmClients.Where(j => j.ClientId == newClient.ClientId); if (insertedClient != null) { return(CreatedAtAction(nameof(newClient), new { id = newClient.ClientId }, newClient)); } } return(BadRequest()); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <ActionResult> Put(int id, [FromBody] BindClient bindClient) { try { if (id != bindClient.ClientId) { return(BadRequest()); } if (!User.HasClaim(claim => (claim.Type == DefinedClaimTypes.RecruiterId && claim.Value == bindClient.RecruiterId.ToString()) || (claim.Type == DefinedClaimTypes.Access && claim.Value == DefinedClaimAccessValues.Elevated))) { return(BadRequest()); } var updatedClient = await _context.CrmClients.FirstOrDefaultAsync(cl => cl.ClientId == bindClient.ClientId); updatedClient.ContactPerson = bindClient.ContactPerson; updatedClient.CompanyName = bindClient.CompanyName; updatedClient.Email = bindClient.Email; updatedClient.TelephoneOffice = bindClient.TelephoneOffice; updatedClient.TelephoneMobile = bindClient.TelephoneMobile; updatedClient.Designation = bindClient.Designation; updatedClient.Remarks = bindClient.Remarks; updatedClient.Address = bindClient.Address; _context.Entry(updatedClient).State = EntityState.Modified; await _context.SaveChangesAsync(); return(NoContent()); } catch { return(BadRequest()); } }
public void BindClient(BindClient command) { Clients.Add(new ClientWorkGroup(command)); }
public ClientWorkGroup(BindClient command) { WorkGroupId = command.WorkgroupId; ClientId = command.ClientId; }