Example #1
0
 public ContactManager(ClientContactCreate command)
 {
     ManagerIdC  = command.ClientId;
     Type        = command.ContactType;
     ManagerId   = command.ManagerId;
     ManagerType = command.ManagerType;
     //IsAccept = command.IsAccept;
     Date = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
 }
Example #2
0
        public async Task <ActionResult <ClientContact> > Put(Guid id, [FromBody] ClientContactCreate entity)
        {
            try
            {
                var client    = _mapper.Map <ClientContact>(entity);
                var itemCount = await _genericService.UpdateAsync(id, client);

                if (itemCount > 0)
                {
                    return(CreatedAtAction(nameof(Get), new { id = client.Id }, client));
                }
                return(NotFound());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Example #3
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));
        }