Beispiel #1
0
        public async Task <IActionResult> Post([FromBody] ClientContactCreate command)
        {
            var clientContact = await _context.Set <ClientContact>()
                                .FirstOrDefaultAsync(x => x.Id == command.Id &&
                                                     x.ClientId == command.ClientId &&
                                                     x.ManagerType == command.ManagerType &&
                                                     x.Date.Date == DateTime.Now.Date.Date);

            //if (clientContact != null)
            //{
            //    clientContact.Type = command.ContactType;
            //    await _context.SaveChangesAsync();
            //    return Ok(null);
            //}

            /*command.ManagerId = _context.Set<ManagerForClient>()
             *  .FirstOrDefault(x => x.ClientId == command.ClientId && x.Type == command.ManagerType)
             *  .Id;*/

            var workGroup = await _context.Set <ClientWorkGroup>()
                            .Where(x => x.ClientId == command.ClientId)
                            .Select(x => new
            {
                RegionalManagerId = x.WorkGroup.RegionalManagerId,
                EscortManagerId   = x.WorkGroup.EscortManagerId
            }).FirstOrDefaultAsync();

            if (command.ManagerType == ManagerType.EscortManager)
            {
                command.ManagerId = (int)workGroup.EscortManagerId;
            }
            else if (command.ManagerType == ManagerType.RegionalManager)
            {
                command.ManagerId = (int)workGroup.RegionalManagerId;
            }
            else
            {
                return(BadRequest("Не указана роль менеджера"));
            }
            ClientContact newClientContact = null;

            if (clientContact != null)
            {
                clientContact.Type = command.ContactType;
                newClientContact   = clientContact;
            }
            else
            {
                newClientContact = _context.Set <ClientContact>()
                                   .Add(new ClientContact(command)).Entity;
            }

            await _context.SaveChangesAsync();

            var result = new ClientContactDto()
            {
                Id          = newClientContact.Id,
                ClientId    = (int)newClientContact.ClientId,
                ContactType = newClientContact.Type,
                Date        = newClientContact.Date.ToString("dd.MM.yyyy"),
                ManagerType = newClientContact.ManagerType
            };

            return(Ok(result));
        }
 public PlacementDto()
 {
     BillingClientContact = new ClientContactDto();
     Candidate            = new CandidateDto();
     JobOrder             = new JobOrderDto();
 }