예제 #1
0
        public async Task <IActionResult> AddOrUpdate([FromForm] Client clientDTO)
        {
            const string API_LOCATE = CONTROLLER_LOCATE + ".AddOrUpdate";

            try
            {
                if (clientDTO.ClientId <= 0)
                {
                    var newClient = new Client()
                    {
                        Email = clientDTO.Email,
                        FIO   = clientDTO.FIO,
                        Phone = clientDTO.Phone,
                        IsIncludeInMailing = clientDTO.IsIncludeInMailing,
                    };
                    await _repository.AddClient(newClient);
                }
                else
                {
                    var oldClient = await _repository.GetClient(clientDTO.ClientId);

                    oldClient.Email = clientDTO.Email;
                    oldClient.FIO   = clientDTO.FIO;
                    oldClient.Phone = clientDTO.Phone;
                    oldClient.IsIncludeInMailing = clientDTO.IsIncludeInMailing;

                    await _repository.UpdateClient(oldClient);
                }

                return(Success(true));
            }
            catch (Exception ex)
            {
                return(LogBadRequest(
                           _logger,
                           API_LOCATE,
                           exception: ex
                           ));
            }
        }