Exemplo n.º 1
0
        public ClientView Update(dynamic clientData)
        {
            var client = Uow.ClientRepository.GetById((int)clientData.Id);

            if (client == null)
            {
                throw new CoralTimeEntityNotFoundException($"Client with id {clientData.Id} not found");
            }

            UpdateService <Client> .UpdateObject(clientData, client);

            BLHelpers.CheckClientsErrors(client);

            // Get all project linked to this client and remember projects that active before an archiving.
            RememberProjectStatusBeforeArchiving(clientData, client);

            try
            {
                Uow.ClientRepository.Update(client);
                Uow.Save();

                Uow.ClientRepository.LinkedCacheClear();
            }
            catch (Exception e)
            {
                throw new CoralTimeDangerException("An error occurred while updating the client", e);
            }

            var resultClient = Uow.ClientRepository.LinkedCacheGetById(client.Id);
            var result       = resultClient.GetView(Mapper);

            return(result);
        }
Exemplo n.º 2
0
        public ClientView Create(ClientView clientData)
        {
            if (!IsNameUnique(clientData.Name))
            {
                throw new CoralTimeAlreadyExistsException($"Client with name {clientData.Name} already exist.");
            }

            var client = Mapper.Map <ClientView, Client>(clientData);

            client.IsActive = true;

            BLHelpers.CheckClientsErrors(client);

            try
            {
                Uow.ClientRepository.Insert(client);
                Uow.Save();

                Uow.ClientRepository.LinkedCacheClear();
            }
            catch (Exception e)
            {
                throw new CoralTimeDangerException("An error occurred while creating new client", e);
            }

            var getClient = Uow.ClientRepository.LinkedCacheGetById(client.Id);

            var result = getClient.GetView(Mapper);

            return(result);
        }